1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-22 04:12:08 +01:00

Added a lot of debug logs to MainActivity

This commit is contained in:
vanitasvitae 2016-09-10 16:54:48 +02:00
parent f58fbd8364
commit b8ba6bb443
4 changed files with 174 additions and 50 deletions

View file

@ -108,7 +108,7 @@ public class MainActivity extends AppCompatActivity
private static final int INPUT_FILE_REQUEST_CODE_NEW = 1;
private static final int INPUT_FILE_REQUEST_CODE_OLD = 2;
private static final int REQUEST_CODE_ASK_PERMISSIONS = 123;
public static final int REQUEST_CODE_ASK_PERMISSIONS_SAVE_IMAGE = 124;
public static final int REQUEST_CODE__ACCESS_EXTERNAL_STORAGE = 124;
public static final String ACTION_OPEN_URL = "com.github.dfa.diaspora_android.MainActivity.open_url";
public static final String ACTION_CHANGE_ACCOUNT = "com.github.dfa.diaspora_android.MainActivity.change_account";
@ -175,20 +175,21 @@ public class MainActivity extends AppCompatActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(App.TAG, "onCreate");
Log.d(App.TAG, "onCreate()");
// Bind UI
setContentView(R.layout.main__activity);
app = (App) getApplication();
appSettings = app.getSettings();
podUserProfile = app.getPodUserProfile();
if ((app = (App) getApplication()) == null) Log.e(App.TAG, "App is null!");
if ((appSettings = app.getSettings()) == null) Log.e(App.TAG, "AppSettings is null!");
if ((podUserProfile = app.getPodUserProfile()) == null) Log.e(App.TAG, "PodUserProfile is null!");
podUserProfile.setCallbackHandler(uiHandler);
podUserProfile.setListener(this);
urls = new DiasporaUrlHelper(appSettings);
if (appSettings.isProxyEnabled()) {
if (!setProxy(appSettings.getProxyHost(), appSettings.getProxyPort())) {
Log.d(App.TAG, "Could not enable Proxy");
Toast.makeText(MainActivity.this, R.string.toast_set_proxy_failed, Toast.LENGTH_SHORT).show();
}
} else if (appSettings.wasProxyEnabled()) {
@ -199,18 +200,22 @@ public class MainActivity extends AppCompatActivity
}
private void setupUI(Bundle savedInstanceState) {
Log.i(App.TAG, "MainActivity.setupUI()");
boolean newWebView = (webView == null);
if(newWebView) {
Log.d(App.TAG, "Webview was null. Create new one.");
Log.v(App.TAG, "Webview was null. Create new one.");
View webviewHolder = getLayoutInflater().inflate(R.layout.webview, this.contentLayout, false);
webView = (ContextMenuWebView) webviewHolder.findViewById(R.id.webView);
((LinearLayout)webView.getParent()).removeView(webView);
setupWebView(savedInstanceState);
} else {
Log.v(App.TAG, "Reuse old WebView to avoid reloading page");
}
ButterKnife.bind(this);
if (webviewPlaceholder.getChildCount() != 0) {
webviewPlaceholder.removeAllViews();
}
Log.v(App.TAG, "Add WebView to placeholder");
webviewPlaceholder.addView(webView);
// Setup toolbar
setSupportActionBar(toolbarTop);
@ -263,19 +268,23 @@ public class MainActivity extends AppCompatActivity
}
if (!appSettings.isIntellihideToolbars()) {
Log.v(App.TAG, "Disable intelligent hiding of toolbars");
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbarTop.getLayoutParams();
params.setScrollFlags(0); // clear all scroll flags
}
Log.v(App.TAG, "UI successfully set up");
handleIntent(getIntent());
}
@Override
public void onConfigurationChanged(Configuration newConfig)
{
Log.i(App.TAG, "onConfigurationChanged()");
if (webView != null)
{
// Remove the WebView from the old placeholder
Log.v(App.TAG, "removeView from placeholder in order to prevent recreation");
webviewPlaceholder.removeView(webView);
}
@ -285,6 +294,7 @@ public class MainActivity extends AppCompatActivity
setContentView(R.layout.main__activity);
// Reinitialize the UI
Log.v(App.TAG, "Rebuild the UI");
setupUI(null);
}
@ -301,6 +311,7 @@ public class MainActivity extends AppCompatActivity
webSettings.setAppCacheEnabled(true);
if (savedInstanceState != null) {
Log.v(App.TAG, "restore WebView state");
webView.restoreState(savedInstanceState);
}
@ -352,17 +363,18 @@ public class MainActivity extends AppCompatActivity
progressBar.setVisibility(progress == 100 ? View.GONE : View.VISIBLE);
}
//For Android 4.1/4.2 only. DONT REMOVE
//For Android 4.1/4.2 only. DO NOT REMOVE!
@SuppressWarnings("unused")
protected void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture)
{
Log.d(App.TAG, "openFileChooser(ValCallback<Uri>, String, String");
Log.v(App.TAG, "openFileChooser(ValCallback<Uri>, String, String");
imageUploadFilePathCallbackOld = uploadMsg;
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra("return-data", true);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
Log.v(App.TAG, "startActivityForResult");
startActivityForResult(Intent.createChooser(intent, "Select Picture"), INPUT_FILE_REQUEST_CODE_OLD);
}
@ -475,17 +487,19 @@ public class MainActivity extends AppCompatActivity
if (!appSettings.getPodDomain().equals("")) {
navheaderDescription.setText(appSettings.getPodDomain());
}
if (!appSettings.getAvatarUrl().equals("")) {
Log.d(App.TAG, "AVATAR URL != \"\": "+appSettings.getAvatarUrl());
String avatarUrl = appSettings.getAvatarUrl();
if (!avatarUrl.equals("")) {
//Display app launcher icon instead of default avatar asset
//(Which would by the way not load because of missing pod domain prefix in the url)
if(appSettings.getAvatarUrl().startsWith("/assets/user/default")) {
if(avatarUrl.startsWith("/assets/user/default")) {
Log.v(App.TAG, "Avatar appears to be an asset. Display launcher icon instead (avatarUrl="+avatarUrl+")");
navheaderImage.setImageResource(R.drawable.ic_launcher);
} else {
// Try to load image
if (!app.getAvatarImageLoader().loadToImageView(navheaderImage)) {
// If not yet loaded, start download
app.getAvatarImageLoader().startImageDownload(navheaderImage, appSettings.getAvatarUrl());
Log.v(App.TAG, "Avatar not cached. Start download: "+avatarUrl);
app.getAvatarImageLoader().startImageDownload(navheaderImage, avatarUrl);
}
}
}
@ -506,6 +520,7 @@ public class MainActivity extends AppCompatActivity
@OnClick(R.id.toolbar)
public void onToolBarClicked(View view) {
Log.i(App.TAG, "MainActivity.onToolBarClicked()");
onNavigationItemSelected(navView.getMenu().findItem(R.id.nav_stream));
}
@ -517,14 +532,16 @@ public class MainActivity extends AppCompatActivity
}
private void handleIntent(Intent intent) {
Log.i(App.TAG, "MainActivity.handleIntent()");
if (intent == null) {
Log.v(App.TAG, "Intent was null");
return;
}
String action = intent.getAction();
String type = intent.getType();
String loadUrl = null;
Log.v(App.TAG, "Action: "+action+" Type: "+type);
if (ACTION_OPEN_URL.equals(action)) {
loadUrl = intent.getStringExtra(URL_MESSAGE);
} else if (Intent.ACTION_VIEW.equals(action) && intent.getDataString() != null) {
@ -536,11 +553,14 @@ public class MainActivity extends AppCompatActivity
loadUrl = intent.getDataString();
}
} else if (ACTION_CHANGE_ACCOUNT.equals(action)) {
Log.v(App.TAG, "Reset pod data and animate to PodSelectionActivity");
app.resetPodData(webView);
Helpers.animateToActivity(MainActivity.this, PodSelectionActivity.class, true);
} else if (ACTION_CLEAR_CACHE.equals(action)) {
Log.v(App.TAG, "Clear WebView cache");
webView.clearCache(true);
} else if (ACTION_RELOAD_ACTIVITY.equals(action)) {
Log.v(App.TAG, "Recreate activity");
recreate();
return;
} else if (Intent.ACTION_SEND.equals(action) && type != null) {
@ -569,10 +589,10 @@ public class MainActivity extends AppCompatActivity
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(App.TAG,"onActivityResult:");
Log.d(App.TAG,"MainActivity.onActivityResult()");
switch (requestCode) {
case INPUT_FILE_REQUEST_CODE_NEW: {
Log.d(App.TAG,"INPUT_FILE_REQUEST_CODE_NEW:");
Log.v(App.TAG,"Upload image using recent method (Lollipop+)");
if (imageUploadFilePathCallbackNew == null || resultCode != Activity.RESULT_OK) {
Log.e(App.TAG, "Callback is null: " + (imageUploadFilePathCallbackNew == null)
+ " resultCode: " + resultCode);
@ -581,20 +601,26 @@ public class MainActivity extends AppCompatActivity
Uri[] results = null;
if (data == null) {
if (mCameraPhotoPath != null) {
Log.v(App.TAG, "Intent data is null. Try to parse cameraPhotoPath");
results = new Uri[]{Uri.parse(mCameraPhotoPath)};
} else {
Log.w(App.TAG, "Intent data is null and cameraPhotoPath is null");
}
} else {
String dataString = data.getDataString();
if (dataString != null) {
Log.v(App.TAG, "Intent has data. Try to parse dataString");
results = new Uri[]{Uri.parse(dataString)};
}
Log.w(App.TAG, "dataString is null");
}
Log.v(App.TAG, "handle received result over to callback");
imageUploadFilePathCallbackNew.onReceiveValue(results);
imageUploadFilePathCallbackNew = null;
return;
}
case INPUT_FILE_REQUEST_CODE_OLD: {
Log.d(App.TAG,"INPUT_FILE_REQUEST_CODE_OLD:");
Log.v(App.TAG, "Upload image using legacy method (Jelly Bean, Kitkat)");
if (imageUploadFilePathCallbackOld == null || resultCode != Activity.RESULT_OK) {
Log.e(App.TAG, "Callback is null: " + (imageUploadFilePathCallbackOld == null)
+ " resultCode: " + resultCode);
@ -603,14 +629,21 @@ public class MainActivity extends AppCompatActivity
Uri results = null;
if (data == null) {
if (mCameraPhotoPath != null) {
Log.v(App.TAG, "Intent has no data. Try to parse cameraPhotoPath");
results = Uri.parse(mCameraPhotoPath);
} else {
Log.w(App.TAG, "Intent has no data and cameraPhotoPath is null");
}
} else {
String dataString = data.getDataString();
if (dataString != null) {
Log.v(App.TAG, "Intent has data. Try to parse dataString");
results = Uri.parse(dataString);
} else {
Log.w(App.TAG, "dataString is null");
}
}
Log.v(App.TAG, "handle received result over to callback");
imageUploadFilePathCallbackOld.onReceiveValue(results);
imageUploadFilePathCallbackOld = null;
return;
@ -621,25 +654,23 @@ public class MainActivity extends AppCompatActivity
@Override
protected void onSaveInstanceState(Bundle outState) {
Log.v(App.TAG, "MainActivity.onSaveInstanceState()");
super.onSaveInstanceState(outState);
Log.v(App.TAG, "Save WebView state");
webView.saveState(outState);
}
@Override
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
Helpers.printBundle(savedInstanceState,"");
Log.v(App.TAG, "MainActivity.onRestoreInstanceState()");
super.onRestoreInstanceState(savedInstanceState);
Log.v(App.TAG, "Restore state of WebView");
webView.restoreState(savedInstanceState);
}
@Override
protected void onResume() {
super.onResume();
LocalBroadcastManager.getInstance(this).registerReceiver(brSetTitle, new IntentFilter(ACTION_UPDATE_TITLE_FROM_URL));
}
@Override
public void onBackPressed() {
Log.v(App.TAG, "MainActivity.onBackPressed()");
if (navDrawer.isDrawerOpen(navView)) {
navDrawer.closeDrawer(navView);
return;
@ -655,12 +686,16 @@ public class MainActivity extends AppCompatActivity
}
}
/**
* BroadcastReceiver that updates the title of the activity based on which url is currently loaded
*/
private final BroadcastReceiver brSetTitle = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String url = intent.getStringExtra(EXTRA_URL);
if (url != null && url.startsWith(urls.getPodUrl())) {
String subUrl = url.substring((urls.getPodUrl()).length());
Log.v(App.TAG, "MainActivity.brSetTitle.onReceive(): Set title for subUrl "+subUrl);
if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_STREAM)) {
setTitle(R.string.nav_stream);
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_POSTS)) {
@ -686,24 +721,38 @@ public class MainActivity extends AppCompatActivity
} else if (urls.isAspectUrl(url)){
setTitle(urls.getAspectNameFromUrl(url, app));
}
} else {
Log.w(App.TAG, "MainActivity.brSetTitle.onReceive(): Invalid url: "+url);
}
}
};
@Override
protected void onPause() {
Log.v(App.TAG, "MainActivity.onPause()");
Log.v(App.TAG, "Unregister BroadcastReceivers");
LocalBroadcastManager.getInstance(this).unregisterReceiver(brSetTitle);
super.onPause();
}
@Override
protected void onResume() {
Log.v(App.TAG, "MainActivity.onResume()");
super.onResume();
Log.v(App.TAG, "Register BroadcastReceivers");
LocalBroadcastManager.getInstance(this).registerReceiver(brSetTitle, new IntentFilter(ACTION_UPDATE_TITLE_FROM_URL));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
Log.v(App.TAG, "MainActivity.onCreateOptionsMenu()");
getMenuInflater().inflate(R.menu.main__menu_top, menu);
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
Log.i(App.TAG, "MainActivity.onPrepareOptionsMenu()");
MenuItem itemNotification = menu.findItem(R.id.action_notifications);
if (itemNotification != null) {
if (podUserProfile.getNotificationCount() > 0) {
@ -724,6 +773,7 @@ public class MainActivity extends AppCompatActivity
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Log.i(App.TAG, "MainActivity.onOptionsItemSelected()");
switch (item.getItemId()) {
case R.id.action_notifications: {
if (WebHelper.isOnline(MainActivity.this)) {
@ -858,6 +908,7 @@ public class MainActivity extends AppCompatActivity
@SuppressWarnings("ResultOfMethodCallIgnored")
private boolean makeScreenshotOfWebView(boolean hasToShareScreenshot) {
Log.i(App.TAG, "MainActivity.makeScreenshotOfWebView()");
if (android.os.Build.VERSION.SDK_INT >= 23) {
int hasWRITE_EXTERNAL_STORAGE = checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) {
@ -888,7 +939,9 @@ public class MainActivity extends AppCompatActivity
String fileSaveName = hasToShareScreenshot ? ".DfA_share.jpg" : String.format("DfA_%s.jpg", dateFormat.format(dateNow));
if (!fileSaveDirectory.exists()) {
fileSaveDirectory.mkdirs();
if(!fileSaveDirectory.mkdirs()) {
Log.w(App.TAG, "Could not mkdir "+fileSaveDirectory.getAbsolutePath());
}
}
if (!hasToShareScreenshot) {
@ -937,21 +990,33 @@ public class MainActivity extends AppCompatActivity
@Override
public void onUserProfileNameChanged(String name) {
Log.i(App.TAG, "MainActivity.onUserProfileNameChanged()");
navheaderTitle.setText(name);
}
@Override
public void onUserProfileAvatarChanged(String avatarUrl) {
Log.i(App.TAG, "MainActivity.onUserProfileAvatarChanged()");
app.getAvatarImageLoader().startImageDownload(navheaderImage, avatarUrl);
}
private void handleHashtag(Intent intent) {
Log.v(App.TAG, "handleHashtag()");
try {
setSharedTexts(null, intent.getData().toString().split("/")[3]);
} catch (Exception e) {
Log.e(App.TAG, e.toString());
}
webView.loadUrlNew(urls.getNewPostUrl());
}
private void handleSendText(Intent intent) {
Log.v(App.TAG, "handleSendText()");
try {
setSharedTexts(null, intent.getStringExtra(Intent.EXTRA_TEXT));
} catch (Exception e) {
Log.e(App.TAG, e.toString());
}
webView.loadUrlNew(urls.getBlankUrl());
webView.loadUrlNew(urls.getNewPostUrl());
}
@ -962,8 +1027,13 @@ public class MainActivity extends AppCompatActivity
* @param intent intent
*/
private void handleSendSubject(Intent intent) {
Log.v(App.TAG, "handleSendSubject()");
try {
setSharedTexts(intent.getStringExtra(Intent.EXTRA_SUBJECT), intent.getStringExtra(Intent.EXTRA_TEXT));
webView.loadUrlNew(urls.getBlankUrl());
} catch (Exception e) {
Log.e(App.TAG, e.toString());
}
webView.loadUrlNew(urls.getBlankUrl()); //TODO: Necessary?
webView.loadUrlNew(urls.getNewPostUrl());
}
@ -976,15 +1046,19 @@ public class MainActivity extends AppCompatActivity
* @param sharedBody post text
*/
private void setSharedTexts(String sharedSubject, String sharedBody) {
Log.i(App.TAG, "MainActivity.setSharedTexts()");
String body = WebHelper.replaceUrlWithMarkdown(sharedBody);
if (appSettings.isAppendSharedViaApp()) {
Log.v(App.TAG, "Append app reference to shared text");
body = body + "\n\n" + getString(R.string.shared_by_diaspora_android);
}
final String escapedBody = WebHelper.escapeHtmlText(body);
if(sharedSubject != null) {
Log.v(App.TAG, "Append subject to shared text");
String escapedSubject = WebHelper.escapeHtmlText(WebHelper.replaceUrlWithMarkdown(sharedSubject));
textToBeShared = "**" + escapedSubject + "** " + escapedBody;
} else {
Log.v(App.TAG, "Set shared text; Subject: \""+sharedSubject+"\" Body: \""+sharedBody+"\"");
textToBeShared = escapedBody;
}
@ -993,9 +1067,13 @@ public class MainActivity extends AppCompatActivity
//TODO: Implement?
private void handleSendImage(Intent intent) {
Log.i(App.TAG, "MainActivity.handleSendImage()");
final Uri imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (imageUri != null) {
Log.v(App.TAG, "imageUri is not null. Handle shared image");
// TODO: Update UI to reflect text being shared
} else {
Log.w(App.TAG, "imageUri is null. Cannot precede.");
}
Toast.makeText(this, "Not yet implemented.", Toast.LENGTH_SHORT).show();
}
@ -1003,6 +1081,7 @@ public class MainActivity extends AppCompatActivity
// TODO: Move from Javascript interface
@Override
public void onNotificationCountChanged(int notificationCount) {
Log.i(App.TAG, "MainActivity.onNotificationCountChanged()");
// Count saved in PodUserProfile
invalidateOptionsMenu();
@ -1015,9 +1094,9 @@ public class MainActivity extends AppCompatActivity
// TODO: Move from Javascript interface
@Override
public void onUnreadMessageCountChanged(int unreadMessageCount) {
Log.i(App.TAG, "MainActivity.onUnreadMessageCountChanged()");
// Count saved in PodUserProfile
invalidateOptionsMenu();
if (unreadMessageCount > 0 && !snackbarNewNotification.isShown()
&& !webView.getUrl().equals(urls.getNotificationsUrl())) {
snackbarNewNotification.show();
@ -1027,8 +1106,12 @@ public class MainActivity extends AppCompatActivity
private class JavaScriptInterface {
@JavascriptInterface
public void setUserProfile(final String webMessage) throws JSONException {
Log.i(App.TAG, "MainActivity.JavaScriptInterface.setUserProfile()");
if (podUserProfile.isRefreshNeeded()) {
Log.v(App.TAG, "PodUserProfile needs refresh; Try to parse JSON");
podUserProfile.parseJson(webMessage);
} else {
Log.v(App.TAG, "No PodUserProfile refresh needed");
}
}
@ -1041,6 +1124,7 @@ public class MainActivity extends AppCompatActivity
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
Log.i(App.TAG, "MainActivity.onNavigationItemsSelected()");
// Handle navigation view item clicks here.
switch (item.getItemId()) {
case R.id.nav_stream: {
@ -1151,10 +1235,12 @@ public class MainActivity extends AppCompatActivity
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case REQUEST_CODE_ASK_PERMISSIONS_SAVE_IMAGE:
case REQUEST_CODE__ACCESS_EXTERNAL_STORAGE:
if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Log.i(App.TAG, "MainActivity.onRequestPermissionsResult: Permission to access external storage granted");
Toast.makeText(this, R.string.permission_granted_try_again, Toast.LENGTH_SHORT).show();
} else {
Log.w(App.TAG, "MainActivity.onRequestPermissionsResult: Permission to access external storage denied");
Toast.makeText(this, R.string.permission_denied, Toast.LENGTH_SHORT).show();
}
return;
@ -1175,25 +1261,35 @@ public class MainActivity extends AppCompatActivity
* @throws IllegalArgumentException if arguments do not fit specifications above
*/
private boolean setProxy(final String host, final int port) {
Log.i(App.TAG, "MainActivity.setProxy()");
if (host != null && !host.equals("") && port >= 0) {
Log.i(App.TAG, "Set proxy to "+host+":"+port);
//Temporary change thread policy
Log.v(App.TAG, "Set temporary ThreadPolicy");
StrictMode.ThreadPolicy old = StrictMode.getThreadPolicy();
StrictMode.ThreadPolicy tmp = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(tmp);
Log.v(App.TAG, "Apply NetCipher proxy settings");
NetCipher.setProxy(host, port); //Proxy for HttpsUrlConnections
try {
//Proxy for the webview
Log.v(App.TAG, "Apply Webkit proxy settings");
WebkitProxy.setProxy(MainActivity.class.getName(), getApplicationContext(), null, host, port);
} catch (Exception e) { /*Nothing we can do*/ }
} catch (Exception e) {
Log.e(App.TAG, "Could not apply WebKit proxy settings:\n"+e.toString());
}
Log.v(App.TAG, "Save changes in appSettings");
appSettings.setProxyEnabled(true);
appSettings.setProxyWasEnabled(true);
Log.v(App.TAG, "Reset old ThreadPolicy");
StrictMode.setThreadPolicy(old);
Log.i(App.TAG, "Success! Reload WebView");
webView.reload();
return true;
} else {
Log.w(App.TAG, "Invalid proxy configuration. Host: "+host+" Port: "+port+"\nRefuse to set proxy");
return false;
}
}
@ -1203,22 +1299,30 @@ public class MainActivity extends AppCompatActivity
}
private void resetProxy() {
Log.i(App.TAG, "MainActivity.resetProxy()");
Log.v(App.TAG, "write changes to appSettings");
appSettings.setProxyEnabled(false);
appSettings.setProxyWasEnabled(false);
//Temporary change thread policy
Log.v(App.TAG, "Set temporary ThreadPolicy");
StrictMode.ThreadPolicy old = StrictMode.getThreadPolicy();
StrictMode.ThreadPolicy tmp = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(tmp);
Log.v(App.TAG, "clear NetCipher proxy");
NetCipher.clearProxy();
try {
Log.v(App.TAG, "clear WebKit proxy");
WebkitProxy.resetProxy(MainActivity.class.getName(), this);
} catch (Exception e) {/*Nothing*/}
} catch (Exception e) {
Log.e(App.TAG, "Could not clear WebKit proxy:\n"+e.toString());
}
Log.v(App.TAG, "Reset old ThreadPolicy");
StrictMode.setThreadPolicy(old);
//Restart app
Log.i(App.TAG, "Success! Restart app due to proxy reset");
Intent restartActivity = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 12374, restartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

View file

@ -19,17 +19,14 @@
package com.github.dfa.diaspora_android.activity;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.util.Helpers;
import butterknife.BindView;
import butterknife.ButterKnife;

View file

@ -96,14 +96,14 @@ public class ContextMenuWebView extends NestedWebView {
public void onClick(DialogInterface dialog, int which) {
if (android.os.Build.VERSION.SDK_INT >= 23)
parentActivity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
MainActivity.REQUEST_CODE_ASK_PERMISSIONS_SAVE_IMAGE);
MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
}
})
.setNegativeButton(context.getText(android.R.string.no), null)
.show();
}
parentActivity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
MainActivity.REQUEST_CODE_ASK_PERMISSIONS_SAVE_IMAGE);
MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
}
}
if (writeToStoragePermitted) {

View file

@ -1,6 +1,6 @@
package com.github.dfa.diaspora_android.util;
import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.data.AppSettings;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@ -13,14 +13,25 @@ import java.util.Observer;
* TODO: Differentiate log types (error/debug/info...)
* Created by vanitas on 09.09.16.
*/
public class Log extends Observable{
public class Log extends Observable {
public static final int MAX_BUFFER_SIZE = 100;
public static Log instance;
private AppSettings appSettings;
private SimpleDateFormat dateFormat;
private ArrayList<String> logBuffer;
private ArrayList<Observer> observers;
private Log() {
this(null);
}
private Log(AppSettings appSettings) {
if(appSettings != null) {
//TODO: Store/Restore logBuffer between app starts
logBuffer = new ArrayList<>();
} else {
logBuffer = new ArrayList<>();
}
dateFormat = new SimpleDateFormat("HH:mm:ss");
observers = new ArrayList<>();
}
@ -30,6 +41,11 @@ public class Log extends Observable{
return instance;
}
public static Log getInstance(AppSettings appSettings) {
if(instance == null) instance = new Log(appSettings);
return instance;
}
private static String time() {
return getInstance().dateFormat.format(new Date())+": ";
}
@ -37,50 +53,50 @@ public class Log extends Observable{
public static void d(String tag, String msg) {
Log l = getInstance();
android.util.Log.d(tag, msg);
l.logBuffer.add(time()+msg);
l.addLogEntry(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.addLogEntry(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.addLogEntry(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.addLogEntry(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.addLogEntry(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.addLogEntry(msg);
l.notifyLogBufferChanged();
}
public static ArrayList<String> getLogBufferArray() {
public synchronized static ArrayList<String> getLogBufferArray() {
return getInstance().logBuffer;
}
public static String getLogBuffer() {
public synchronized static String getLogBuffer() {
String out = "";
for(String s : getInstance().logBuffer) {
out = out + s + "\n";
@ -97,6 +113,13 @@ public class Log extends Observable{
}
}
private synchronized void addLogEntry(String msg) {
logBuffer.add(time()+msg);
while (logBuffer.size() > MAX_BUFFER_SIZE) {
logBuffer.remove(0);
}
}
public static void addLogObserver(Observer observer) {
getInstance().observers.add(observer);
}