diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a35c1683..1b17865a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -41,7 +41,7 @@ android:name=".activity.SettingsActivity" android:launchMode="singleInstance" android:theme="@style/AppTheme" - android:label="@string/pref_title__personal_settings"> + android:label="@string/settings"> . */ - + package com.github.dfa.diaspora_android; import android.app.Application; @@ -29,11 +29,11 @@ import android.webkit.WebView; import com.github.dfa.diaspora_android.data.AppSettings; import com.github.dfa.diaspora_android.data.PodUserProfile; +import com.github.dfa.diaspora_android.util.AppLog; import com.github.dfa.diaspora_android.util.AvatarImageLoader; import com.github.dfa.diaspora_android.util.DiasporaUrlHelper; public class App extends Application { - public static final String TAG = "DIASPORA_"; private AppSettings appSettings; private AvatarImageLoader avatarImageLoader; @@ -45,6 +45,12 @@ public class App extends Application { super.onCreate(); final Context c = getApplicationContext(); appSettings = new AppSettings(c); + + // Init app log + AppLog.setLoggingEnabled(appSettings.isLoggingEnabled()); + AppLog.setLoggingSpamEnabled(appSettings.isLoggingSpamEnabled()); + + // Init pod profile avatarImageLoader = new AvatarImageLoader(c); podUserProfile = new PodUserProfile(this); @@ -58,8 +64,8 @@ public class App extends Application { cookieManager.setAcceptCookie(true); } - public void resetPodData(@Nullable WebView webView){ - if(webView != null){ + public void resetPodData(@Nullable WebView webView) { + if (webView != null) { webView.stopLoading(); webView.loadUrl(DiasporaUrlHelper.URL_BLANK); webView.clearFormData(); @@ -81,7 +87,7 @@ public class App extends Application { } } - public PodUserProfile getPodUserProfile(){ + public PodUserProfile getPodUserProfile() { return podUserProfile; } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/activity/AboutActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/activity/AboutActivity.java index c8df19ad..492dcc55 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/activity/AboutActivity.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/activity/AboutActivity.java @@ -44,10 +44,10 @@ import com.github.dfa.diaspora_android.App; 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.AppLog; 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; @@ -94,7 +94,7 @@ public class AboutActivity extends AppCompatActivity { tabLayout.setupWithViewPager(mViewPager); //Apply intellihide - if(!((App)getApplication()).getSettings().isIntellihideToolbars()) { + if (!((App) getApplication()).getSettings().isIntellihideToolbars()) { AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) linearLayout.getLayoutParams(); params.setScrollFlags(0); } @@ -194,6 +194,7 @@ public class AboutActivity extends AppCompatActivity { */ public static class DebugFragment extends Fragment implements Observer { private TextView logBox; + public DebugFragment() { } @@ -210,14 +211,15 @@ public class AboutActivity extends AppCompatActivity { logBox.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { - Log.d(App.TAG, "Long click registered"); - if(isAdded()) { + AppLog.d(this, "Long click registered"); + if (isAdded()) { ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("DEBUG_LOG", Log.getLogBuffer()); clipboard.setPrimaryClip(clip); Toast.makeText(DebugFragment.this.getActivity(), R.string.fragment_debug__toast_log_copied, Toast.LENGTH_SHORT).show(); + } else { + AppLog.d(this, "Not Added!"); } - else Log.d(App.TAG, "Not Added!"); return true; } }); @@ -233,7 +235,7 @@ public class AboutActivity extends AppCompatActivity { appVersion.setText(getString(R.string.fragment_debug__app_version, pInfo.versionName + " (" + pInfo.versionCode + ")")); osVersion.setText(getString(R.string.fragment_debug__android_version, Build.VERSION.RELEASE)); - deviceName.setText(getString(R.string.fragment_debug__device_name, Build.MANUFACTURER+" "+Build.MODEL)); + deviceName.setText(getString(R.string.fragment_debug__device_name, Build.MANUFACTURER + " " + Build.MODEL)); podDomain.setText(getString(R.string.fragment_debug__pod_domain, settings.getPodDomain())); } catch (PackageManager.NameNotFoundException e) { @@ -252,7 +254,7 @@ public class AboutActivity extends AppCompatActivity { @Override public void update(Observable observable, Object o) { - if(logBox != null) { + if (logBox != null) { logBox.setText(Log.getLogBuffer()); } } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java index bbe82baf..22dbd5d8 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java @@ -26,8 +26,6 @@ import android.app.AlarmManager; import android.app.AlertDialog; import android.app.PendingIntent; import android.content.BroadcastReceiver; -import android.graphics.drawable.LayerDrawable; -import android.support.v4.view.MenuItemCompat; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -35,7 +33,7 @@ import android.content.IntentFilter; import android.content.pm.PackageManager; import android.content.res.Configuration; import android.graphics.Bitmap; -import android.graphics.BitmapFactory; +import android.graphics.drawable.LayerDrawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -44,7 +42,6 @@ import android.os.Handler; import android.os.StrictMode; import android.provider.MediaStore; import android.support.annotation.NonNull; -import android.support.customtabs.CustomTabsIntent; import android.support.design.widget.AppBarLayout; import android.support.design.widget.NavigationView; import android.support.design.widget.Snackbar; @@ -86,11 +83,10 @@ import com.github.dfa.diaspora_android.receivers.UpdateTitleReceiver; import com.github.dfa.diaspora_android.ui.BadgeDrawable; import com.github.dfa.diaspora_android.ui.ContextMenuWebView; import com.github.dfa.diaspora_android.ui.CustomWebViewClient; -import com.github.dfa.diaspora_android.util.CustomTabHelpers.BrowserFallback; +import com.github.dfa.diaspora_android.util.AppLog; import com.github.dfa.diaspora_android.util.CustomTabHelpers.CustomTabActivityHelper; 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; @@ -188,14 +184,15 @@ public class MainActivity extends AppCompatActivity @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Log.d(App.TAG, "onCreate()"); + AppLog.v(this, "onCreate()"); // Bind UI setContentView(R.layout.main__activity); - 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!"); + if ((app = (App) getApplication()) == null) AppLog.e(this, "App is null!"); + if ((appSettings = app.getSettings()) == null) AppLog.e(this, "AppSettings is null!"); + if ((podUserProfile = app.getPodUserProfile()) == null) + AppLog.e(this, "PodUserProfile is null!"); podUserProfile.setCallbackHandler(uiHandler); podUserProfile.setListener(this); urls = new DiasporaUrlHelper(appSettings); @@ -205,7 +202,7 @@ public class MainActivity extends AppCompatActivity if (appSettings.isProxyEnabled()) { if (!setProxy(appSettings.getProxyHost(), appSettings.getProxyPort())) { - Log.d(App.TAG, "Could not enable Proxy"); + AppLog.e(this, "Could not enable Proxy"); Toast.makeText(MainActivity.this, R.string.toast_set_proxy_failed, Toast.LENGTH_SHORT).show(); } } else if (appSettings.wasProxyEnabled()) { @@ -227,27 +224,27 @@ public class MainActivity extends AppCompatActivity } private void setupUI(Bundle savedInstanceState) { - Log.i(App.TAG, "MainActivity.setupUI()"); + AppLog.i(this, "setupUI()"); ButterKnife.bind(this); if (webviewPlaceholder.getChildCount() != 0) { - Log.v(App.TAG, "remove child views from webViewPlaceholder"); + AppLog.v(this, "remove child views from webViewPlaceholder"); webviewPlaceholder.removeAllViews(); } else { - Log.v(App.TAG, "webViewPlaceholder had no child views"); + AppLog.v(this, "webViewPlaceholder had no child views"); } boolean newWebView = (webView == null); - if(newWebView) { - Log.v(App.TAG, "WebView was null. Create new one."); + if (newWebView) { + AppLog.v(this, "WebView was null. Create new one."); View webviewHolder = getLayoutInflater().inflate(R.layout.webview, this.contentLayout, false); this.webView = (ContextMenuWebView) webviewHolder.findViewById(R.id.webView); - ((LinearLayout)webView.getParent()).removeView(webView); + ((LinearLayout) webView.getParent()).removeView(webView); setupWebView(savedInstanceState); } else { - Log.v(App.TAG, "Reuse old WebView to avoid reloading page"); + AppLog.v(this, "Reuse old WebView to avoid reloading page"); } - Log.v(App.TAG, "Add WebView to placeholder"); + AppLog.v(this, "Add WebView to placeholder"); webviewPlaceholder.addView(webView); // Setup toolbar setSupportActionBar(toolbarTop); @@ -291,7 +288,7 @@ public class MainActivity extends AppCompatActivity String url = urls.getPodUrl(); if (newWebView) { if (WebHelper.isOnline(MainActivity.this)) { - Log.d(App.TAG, "setupUI: reload url"); + AppLog.v(this, "setupUI: reload url"); webView.loadData("", "text/html", null); webView.loadUrlNew(url); } else { @@ -300,23 +297,21 @@ public class MainActivity extends AppCompatActivity } if (!appSettings.isIntellihideToolbars()) { - Log.v(App.TAG, "Disable intelligent hiding of toolbars"); + AppLog.v(this, "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"); + AppLog.v(this, "UI successfully set up"); handleIntent(getIntent()); } @Override - public void onConfigurationChanged(Configuration newConfig) - { - Log.i(App.TAG, "onConfigurationChanged()"); - if (webView != null) - { + public void onConfigurationChanged(Configuration newConfig) { + AppLog.i(this, "onConfigurationChanged()"); + if (webView != null) { // Remove the WebView from the old placeholder - Log.v(App.TAG, "removeView from placeholder in order to prevent recreation"); + AppLog.v(this, "removeView from placeholder in order to prevent recreation"); webviewPlaceholder.removeView(webView); } @@ -326,7 +321,7 @@ public class MainActivity extends AppCompatActivity setContentView(R.layout.main__activity); // Reinitialize the UI - Log.v(App.TAG, "Rebuild the UI"); + AppLog.v(this, "Rebuild the UI"); setupUI(null); } @@ -343,7 +338,7 @@ public class MainActivity extends AppCompatActivity webSettings.setAppCacheEnabled(true); if (savedInstanceState != null) { - Log.v(App.TAG, "restore WebView state"); + AppLog.v(this, "restore WebView state"); webView.restoreState(savedInstanceState); } @@ -397,22 +392,21 @@ public class MainActivity extends AppCompatActivity //For Android 4.1/4.2 only. DO NOT REMOVE! @SuppressWarnings("unused") - protected void openFileChooser(ValueCallback uploadMsg, String acceptType, String capture) - { - Log.v(App.TAG, "openFileChooser(ValCallback, String, String"); + protected void openFileChooser(ValueCallback uploadMsg, String acceptType, String capture) { + AppLog.v(this, "openFileChooser(ValCallback, 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"); + AppLog.v(this, "startActivityForResult"); startActivityForResult(Intent.createChooser(intent, "Select Picture"), INPUT_FILE_REQUEST_CODE_OLD); } @Override public boolean onShowFileChooser(WebView webView, ValueCallback filePathCallback, FileChooserParams fileChooserParams) { - if(Build.VERSION.SDK_INT >= 23) { + if (Build.VERSION.SDK_INT >= 23) { int hasWRITE_EXTERNAL_STORAGE = checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE); if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) { if (!shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { @@ -436,8 +430,9 @@ public class MainActivity extends AppCompatActivity } } - Log.d(App.TAG, "onOpenFileChooser"); - if (imageUploadFilePathCallbackNew != null) imageUploadFilePathCallbackNew.onReceiveValue(null); + AppLog.v(this, "onOpenFileChooser"); + if (imageUploadFilePathCallbackNew != null) + imageUploadFilePathCallbackNew.onReceiveValue(null); imageUploadFilePathCallbackNew = filePathCallback; Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); @@ -448,7 +443,7 @@ public class MainActivity extends AppCompatActivity photoFile = Helpers.createImageFile(); takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath); } catch (IOException ex) { - Log.e(App.TAG, "ERROR creating temp file: "+ ex.toString()); + AppLog.e(this, "ERROR creating temp file: " + ex.toString()); // Error occurred while creating the File Snackbar.make(contentLayout, R.string.unable_to_load_image, Snackbar.LENGTH_LONG).show(); return false; @@ -480,7 +475,7 @@ public class MainActivity extends AppCompatActivity chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); - Log.d(App.TAG,"startActivityForResult"); + AppLog.v(this, "startActivityForResult"); startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE_NEW); return true; } @@ -523,14 +518,14 @@ public class MainActivity extends AppCompatActivity 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(avatarUrl.startsWith("/assets/user/default")) { - Log.v(App.TAG, "Avatar appears to be an asset. Display launcher icon instead (avatarUrl="+avatarUrl+")"); + if (avatarUrl.startsWith("/assets/user/default")) { + AppLog.v(this, "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 - Log.v(App.TAG, "Avatar not cached. Start download: "+avatarUrl); + AppLog.v(this, "Avatar not cached. Start download: " + avatarUrl); app.getAvatarImageLoader().startImageDownload(navheaderImage, avatarUrl); } } @@ -552,7 +547,7 @@ public class MainActivity extends AppCompatActivity @OnClick(R.id.toolbar) public void onToolBarClicked(View view) { - Log.i(App.TAG, "MainActivity.onToolBarClicked()"); + AppLog.i(this, "onToolBarClicked()"); onNavigationItemSelected(navView.getMenu().findItem(R.id.nav_stream)); } @@ -564,35 +559,35 @@ public class MainActivity extends AppCompatActivity } private void handleIntent(Intent intent) { - Log.i(App.TAG, "MainActivity.handleIntent()"); + AppLog.i(this, "handleIntent()"); if (intent == null) { - Log.v(App.TAG, "Intent was null"); + AppLog.v(this, "Intent was null"); return; } String action = intent.getAction(); String type = intent.getType(); String loadUrl = null; - Log.v(App.TAG, "Action: "+action+" Type: "+type); + AppLog.v(this, "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) { Uri data = intent.getData(); - if(data != null && data.toString().startsWith(CONTENT_HASHTAG)) { + if (data != null && data.toString().startsWith(CONTENT_HASHTAG)) { handleHashtag(intent); return; } else { loadUrl = intent.getDataString(); } } else if (ACTION_CHANGE_ACCOUNT.equals(action)) { - Log.v(App.TAG, "Reset pod data and animate to PodSelectionActivity"); + AppLog.v(this, "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"); + AppLog.v(this, "Clear WebView cache"); webView.clearCache(true); } else if (ACTION_RELOAD_ACTIVITY.equals(action)) { - Log.v(App.TAG, "Recreate activity"); + AppLog.v(this, "Recreate activity"); recreate(); return; } else if (Intent.ACTION_SEND.equals(action) && type != null) { @@ -621,61 +616,61 @@ public class MainActivity extends AppCompatActivity @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { - Log.d(App.TAG,"MainActivity.onActivityResult()"); + AppLog.v(this, "onActivityResult()"); switch (requestCode) { case INPUT_FILE_REQUEST_CODE_NEW: { - Log.v(App.TAG,"Upload image using recent method (Lollipop+)"); + AppLog.v(this, "Upload image using recent method (Lollipop+)"); if (imageUploadFilePathCallbackNew == null || resultCode != Activity.RESULT_OK) { - Log.e(App.TAG, "Callback is null: " + (imageUploadFilePathCallbackNew == null) + AppLog.e(this, "Callback is null: " + (imageUploadFilePathCallbackNew == null) + " resultCode: " + resultCode); return; } Uri[] results = null; if (data == null) { if (mCameraPhotoPath != null) { - Log.v(App.TAG, "Intent data is null. Try to parse cameraPhotoPath"); + AppLog.v(this, "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"); + AppLog.w(this, "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"); + AppLog.v(this, "Intent has data. Try to parse dataString"); results = new Uri[]{Uri.parse(dataString)}; } - Log.w(App.TAG, "dataString is null"); + AppLog.w(this, "dataString is null"); } - Log.v(App.TAG, "handle received result over to callback"); + AppLog.v(this, "handle received result over to callback"); imageUploadFilePathCallbackNew.onReceiveValue(results); imageUploadFilePathCallbackNew = null; return; } case INPUT_FILE_REQUEST_CODE_OLD: { - Log.v(App.TAG, "Upload image using legacy method (Jelly Bean, Kitkat)"); + AppLog.v(this, "Upload image using legacy method (Jelly Bean, Kitkat)"); if (imageUploadFilePathCallbackOld == null || resultCode != Activity.RESULT_OK) { - Log.e(App.TAG, "Callback is null: " + (imageUploadFilePathCallbackOld == null) + AppLog.e(this, "Callback is null: " + (imageUploadFilePathCallbackOld == null) + " resultCode: " + resultCode); return; } Uri results = null; if (data == null) { if (mCameraPhotoPath != null) { - Log.v(App.TAG, "Intent has no data. Try to parse cameraPhotoPath"); + AppLog.v(this, "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"); + AppLog.w(this, "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"); + AppLog.v(this, "Intent has data. Try to parse dataString"); results = Uri.parse(dataString); } else { - Log.w(App.TAG, "dataString is null"); + AppLog.w(this, "dataString is null"); } } - Log.v(App.TAG, "handle received result over to callback"); + AppLog.v(this, "handle received result over to callback"); imageUploadFilePathCallbackOld.onReceiveValue(results); imageUploadFilePathCallbackOld = null; return; @@ -686,23 +681,23 @@ public class MainActivity extends AppCompatActivity @Override protected void onSaveInstanceState(Bundle outState) { - Log.v(App.TAG, "MainActivity.onSaveInstanceState()"); + AppLog.v(this, "onSaveInstanceState()"); super.onSaveInstanceState(outState); - Log.v(App.TAG, "Save WebView state"); + AppLog.v(this, "Save WebView state"); webView.saveState(outState); } @Override protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { - Log.v(App.TAG, "MainActivity.onRestoreInstanceState()"); + AppLog.v(this, "onRestoreInstanceState()"); super.onRestoreInstanceState(savedInstanceState); - Log.v(App.TAG, "Restore state of WebView"); + AppLog.v(this, "Restore state of WebView"); webView.restoreState(savedInstanceState); } @Override public void onBackPressed() { - Log.v(App.TAG, "MainActivity.onBackPressed()"); + AppLog.v(this, "onBackPressed()"); if (navDrawer.isDrawerOpen(navView)) { navDrawer.closeDrawer(navView); return; @@ -732,8 +727,8 @@ public class MainActivity extends AppCompatActivity @Override protected void onPause() { - Log.v(App.TAG, "MainActivity.onPause()"); - Log.v(App.TAG, "Unregister BroadcastReceivers"); + AppLog.v(this, "onPause()"); + AppLog.v(this, "Unregister BroadcastReceivers"); LocalBroadcastManager.getInstance(this).unregisterReceiver(brSetTitle); LocalBroadcastManager.getInstance(this).unregisterReceiver(brOpenExternalLink); super.onPause(); @@ -741,16 +736,16 @@ public class MainActivity extends AppCompatActivity @Override protected void onResume() { - Log.v(App.TAG, "MainActivity.onResume()"); + AppLog.v(this, "onResume()"); super.onResume(); - Log.v(App.TAG, "Register BroadcastReceivers"); + AppLog.v(this, "Register BroadcastReceivers"); LocalBroadcastManager.getInstance(this).registerReceiver(brSetTitle, new IntentFilter(ACTION_UPDATE_TITLE_FROM_URL)); LocalBroadcastManager.getInstance(this).registerReceiver(brOpenExternalLink, new IntentFilter(ACTION_OPEN_EXTERNAL_URL)); } @Override public boolean onCreateOptionsMenu(Menu menu) { - Log.v(App.TAG, "MainActivity.onCreateOptionsMenu()"); + AppLog.v(this, "onCreateOptionsMenu()"); getMenuInflater().inflate(R.menu.main__menu_top, menu); return true; } @@ -773,7 +768,7 @@ public class MainActivity extends AppCompatActivity @Override public boolean onOptionsItemSelected(MenuItem item) { - Log.i(App.TAG, "MainActivity.onOptionsItemSelected()"); + AppLog.i(this, "onOptionsItemSelected()"); switch (item.getItemId()) { case R.id.action_notifications: { if (WebHelper.isOnline(MainActivity.this)) { @@ -862,7 +857,7 @@ public class MainActivity extends AppCompatActivity @Override public void onClick(DialogInterface dialogInterface, int which) { String query = input.getText().toString().trim().replaceAll((which == DialogInterface.BUTTON_NEGATIVE ? "\\*" : "\\#"), ""); - if(query.equals("")) { + if (query.equals("")) { Snackbar.make(contentLayout, R.string.search_alert_bypeople_validate_needsomedata, Snackbar.LENGTH_LONG).show(); } else { webView.loadUrl(which == DialogInterface.BUTTON_NEGATIVE ? urls.getSearchPeopleUrl(query) : urls.getSearchTagsUrl(query)); @@ -908,7 +903,7 @@ public class MainActivity extends AppCompatActivity @SuppressWarnings("ResultOfMethodCallIgnored") private boolean makeScreenshotOfWebView(boolean hasToShareScreenshot) { - Log.i(App.TAG, "MainActivity.makeScreenshotOfWebView()"); + AppLog.i(this, "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) { @@ -939,8 +934,8 @@ public class MainActivity extends AppCompatActivity String fileSaveName = hasToShareScreenshot ? ".DfA_share.jpg" : String.format("DfA_%s.jpg", dateFormat.format(dateNow)); if (!fileSaveDirectory.exists()) { - if(!fileSaveDirectory.mkdirs()) { - Log.w(App.TAG, "Could not mkdir "+fileSaveDirectory.getAbsolutePath()); + if (!fileSaveDirectory.mkdirs()) { + AppLog.w(this, "Could not mkdir " + fileSaveDirectory.getAbsolutePath()); } } @@ -990,32 +985,32 @@ public class MainActivity extends AppCompatActivity @Override public void onUserProfileNameChanged(String name) { - Log.i(App.TAG, "MainActivity.onUserProfileNameChanged()"); + AppLog.i(this, "onUserProfileNameChanged()"); navheaderTitle.setText(name); } @Override public void onUserProfileAvatarChanged(String avatarUrl) { - Log.i(App.TAG, "MainActivity.onUserProfileAvatarChanged()"); + AppLog.i(this, "onUserProfileAvatarChanged()"); app.getAvatarImageLoader().startImageDownload(navheaderImage, avatarUrl); } private void handleHashtag(Intent intent) { - Log.v(App.TAG, "handleHashtag()"); + AppLog.v(this, "handleHashtag()"); try { setSharedTexts(null, intent.getData().toString().split("/")[3]); } catch (Exception e) { - Log.e(App.TAG, e.toString()); + AppLog.e(this, e.toString()); } webView.loadUrlNew(urls.getNewPostUrl()); } private void handleSendText(Intent intent) { - Log.v(App.TAG, "handleSendText()"); + AppLog.v(this, "handleSendText()"); try { setSharedTexts(null, intent.getStringExtra(Intent.EXTRA_TEXT)); } catch (Exception e) { - Log.e(App.TAG, e.toString()); + AppLog.e(this, e.toString()); } webView.loadUrlNew(urls.getBlankUrl()); webView.loadUrlNew(urls.getNewPostUrl()); @@ -1027,11 +1022,11 @@ public class MainActivity extends AppCompatActivity * @param intent intent */ private void handleSendSubject(Intent intent) { - Log.v(App.TAG, "handleSendSubject()"); + AppLog.v(this, "handleSendSubject()"); try { setSharedTexts(intent.getStringExtra(Intent.EXTRA_SUBJECT), intent.getStringExtra(Intent.EXTRA_TEXT)); } catch (Exception e) { - Log.e(App.TAG, e.toString()); + AppLog.e(this, e.toString()); } webView.loadUrlNew(urls.getBlankUrl()); //TODO: Necessary? webView.loadUrlNew(urls.getNewPostUrl()); @@ -1042,23 +1037,24 @@ public class MainActivity extends AppCompatActivity * If subject is null, only the body will be set. Else the subject will be set as header. * Depending on whether the user has the setting isAppendSharedViaApp set, a reference to * the app will be added at the bottom + * * @param sharedSubject post subject or null - * @param sharedBody post text + * @param sharedBody post text */ private void setSharedTexts(String sharedSubject, String sharedBody) { - Log.i(App.TAG, "MainActivity.setSharedTexts()"); + AppLog.i(this, "setSharedTexts()"); String body = WebHelper.replaceUrlWithMarkdown(sharedBody); if (appSettings.isAppendSharedViaApp()) { - Log.v(App.TAG, "Append app reference to shared text"); + AppLog.v(this, "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"); + if (sharedSubject != null) { + AppLog.v(this, "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+"\""); + AppLog.v(this, "Set shared text; Subject: \"" + sharedSubject + "\" Body: \"" + sharedBody + "\""); textToBeShared = escapedBody; } @@ -1067,13 +1063,13 @@ public class MainActivity extends AppCompatActivity //TODO: Implement? private void handleSendImage(Intent intent) { - Log.i(App.TAG, "MainActivity.handleSendImage()"); + AppLog.i(this, "handleSendImage()"); final Uri imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM); if (imageUri != null) { - Log.v(App.TAG, "imageUri is not null. Handle shared image"); + AppLog.v(this, "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."); + AppLog.w(this, "imageUri is null. Cannot precede."); } Toast.makeText(this, "Not yet implemented.", Toast.LENGTH_SHORT).show(); } @@ -1081,7 +1077,7 @@ public class MainActivity extends AppCompatActivity // TODO: Move from Javascript interface @Override public void onNotificationCountChanged(int notificationCount) { - Log.i(App.TAG, "MainActivity.onNotificationCountChanged()"); + AppLog.i(this, "onNotificationCountChanged()"); // Count saved in PodUserProfile invalidateOptionsMenu(); @@ -1094,7 +1090,7 @@ public class MainActivity extends AppCompatActivity // TODO: Move from Javascript interface @Override public void onUnreadMessageCountChanged(int unreadMessageCount) { - Log.i(App.TAG, "MainActivity.onUnreadMessageCountChanged()"); + AppLog.i(this, "onUnreadMessageCountChanged()"); // Count saved in PodUserProfile invalidateOptionsMenu(); if (unreadMessageCount > 0 && !snackbarNewNotification.isShown() @@ -1106,12 +1102,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()"); + AppLog.spam(this, "JavaScriptInterface.setUserProfile()"); if (podUserProfile.isRefreshNeeded()) { - Log.v(App.TAG, "PodUserProfile needs refresh; Try to parse JSON"); + AppLog.spam(this, "PodUserProfile needs refresh; Try to parse JSON"); podUserProfile.parseJson(webMessage); } else { - Log.v(App.TAG, "No PodUserProfile refresh needed"); + AppLog.spam(this, "No PodUserProfile refresh needed"); } } @@ -1124,7 +1120,7 @@ public class MainActivity extends AppCompatActivity @SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { - Log.i(App.TAG, "MainActivity.onNavigationItemsSelected()"); + AppLog.v(this, "onNavigationItemsSelected()"); // Handle navigation view item clicks here. switch (item.getItemId()) { case R.id.nav_stream: { @@ -1237,10 +1233,10 @@ public class MainActivity extends AppCompatActivity switch (requestCode) { 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"); + AppLog.i(this, "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"); + AppLog.w(this, "onRequestPermissionsResult: Permission to access external storage denied"); Toast.makeText(this, R.string.permission_denied, Toast.LENGTH_SHORT).show(); } return; @@ -1261,35 +1257,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()"); + AppLog.v(this, "setProxy()"); if (host != null && !host.equals("") && port >= 0) { - Log.i(App.TAG, "Set proxy to "+host+":"+port); + AppLog.v(this, "Set proxy to " + host + ":" + port); //Temporary change thread policy - Log.v(App.TAG, "Set temporary ThreadPolicy"); + AppLog.v(this, "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"); + AppLog.v(this, "Apply NetCipher proxy settings"); NetCipher.setProxy(host, port); //Proxy for HttpsUrlConnections try { //Proxy for the webview - Log.v(App.TAG, "Apply Webkit proxy settings"); + AppLog.v(this, "Apply Webkit proxy settings"); WebkitProxy.setProxy(MainActivity.class.getName(), getApplicationContext(), null, host, port); } catch (Exception e) { - Log.e(App.TAG, "Could not apply WebKit proxy settings:\n"+e.toString()); + AppLog.e(this, "Could not apply WebKit proxy settings:\n" + e.toString()); } - Log.v(App.TAG, "Save changes in appSettings"); + AppLog.v(this, "Save changes in appSettings"); appSettings.setProxyEnabled(true); appSettings.setProxyWasEnabled(true); - Log.v(App.TAG, "Reset old ThreadPolicy"); + AppLog.v(this, "Reset old ThreadPolicy"); StrictMode.setThreadPolicy(old); - Log.i(App.TAG, "Success! Reload WebView"); + AppLog.v(this, "Success! Reload WebView"); webView.reload(); return true; } else { - Log.w(App.TAG, "Invalid proxy configuration. Host: "+host+" Port: "+port+"\nRefuse to set proxy"); + AppLog.w(this, "Invalid proxy configuration. Host: " + host + " Port: " + port + "\nRefuse to set proxy"); return false; } } @@ -1299,30 +1295,30 @@ public class MainActivity extends AppCompatActivity } private void resetProxy() { - Log.i(App.TAG, "MainActivity.resetProxy()"); - Log.v(App.TAG, "write changes to appSettings"); + AppLog.i(this, "resetProxy()"); + AppLog.v(this, "write changes to appSettings"); appSettings.setProxyEnabled(false); appSettings.setProxyWasEnabled(false); //Temporary change thread policy - Log.v(App.TAG, "Set temporary ThreadPolicy"); + AppLog.v(this, "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"); + AppLog.v(this, "clear NetCipher proxy"); NetCipher.clearProxy(); try { - Log.v(App.TAG, "clear WebKit proxy"); + AppLog.v(this, "clear WebKit proxy"); WebkitProxy.resetProxy(MainActivity.class.getName(), this); } catch (Exception e) { - Log.e(App.TAG, "Could not clear WebKit proxy:\n"+e.toString()); + AppLog.e(this, "Could not clear WebKit proxy:\n" + e.toString()); } - Log.v(App.TAG, "Reset old ThreadPolicy"); + AppLog.v(this, "Reset old ThreadPolicy"); StrictMode.setThreadPolicy(old); //Restart app - Log.i(App.TAG, "Success! Restart app due to proxy reset"); + AppLog.i(this, "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); diff --git a/app/src/main/java/com/github/dfa/diaspora_android/activity/SettingsActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/activity/SettingsActivity.java index 94554385..88f13171 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/activity/SettingsActivity.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/activity/SettingsActivity.java @@ -34,6 +34,8 @@ import android.view.MenuItem; import com.github.dfa.diaspora_android.App; import com.github.dfa.diaspora_android.R; +import com.github.dfa.diaspora_android.data.AppSettings; +import com.github.dfa.diaspora_android.util.AppLog; /** * @author vanitas @@ -45,14 +47,13 @@ public class SettingsActivity extends AppCompatActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ActionBar toolbar = getSupportActionBar(); - if(toolbar != null) + if (toolbar != null) toolbar.setDisplayHomeAsUpEnabled(true); getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit(); } @Override - public boolean onOptionsItemSelected(MenuItem menuItem) - { + public boolean onOptionsItemSelected(MenuItem menuItem) { switch (menuItem.getItemId()) { case android.R.id.home: onBackPressed(); @@ -93,7 +94,7 @@ public class SettingsActivity extends AppCompatActivity { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { updatePreference(findPreference(key)); - if(key != null && isAdded() && (key.equals(getString(R.string.pref_key__clear_cache)) || + if (key != null && isAdded() && (key.equals(getString(R.string.pref_key__clear_cache)) || key.equals(getString(R.string.pref_key__font_size)) || key.equals(getString(R.string.pref_key__load_images)) || key.equals(getString(R.string.pref_key__intellihide_toolbars)) || @@ -157,6 +158,7 @@ public class SettingsActivity extends AppCompatActivity { .show(); return true; } + default: { intent = null; break; @@ -171,6 +173,16 @@ public class SettingsActivity extends AppCompatActivity { } } + @Override + protected void onPause() { + super.onPause(); + + // Reset logging + AppSettings settings = new AppSettings(getApplicationContext()); + AppLog.setLoggingEnabled(settings.isLoggingEnabled()); + AppLog.setLoggingSpamEnabled(settings.isLoggingSpamEnabled()); + } + @Override protected void onStop() { super.onStop(); diff --git a/app/src/main/java/com/github/dfa/diaspora_android/data/AppSettings.java b/app/src/main/java/com/github/dfa/diaspora_android/data/AppSettings.java index e4ba46a7..b8135e86 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/data/AppSettings.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/data/AppSettings.java @@ -260,6 +260,14 @@ public class AppSettings { return getBoolean(prefApp, R.string.pref_key__chrome_custom_tabs_enabled, true); } + public boolean isLoggingEnabled() { + return getBoolean(prefApp, R.string.pref_key__logging_enabled, true); + } + + public boolean isLoggingSpamEnabled() { + return getBoolean(prefApp, R.string.pref_key__logging_spam_enabled, false); + } + public boolean isVisibleInNavExit() { return getBoolean(prefApp, R.string.pref_key__visibility_nav__exit, false); } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/data/PodUserProfile.java b/app/src/main/java/com/github/dfa/diaspora_android/data/PodUserProfile.java index bbc90500..b670513c 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/data/PodUserProfile.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/data/PodUserProfile.java @@ -19,6 +19,8 @@ package com.github.dfa.diaspora_android.data; import android.os.Handler; + +import com.github.dfa.diaspora_android.util.AppLog; import com.github.dfa.diaspora_android.util.Log; import com.github.dfa.diaspora_android.App; @@ -126,7 +128,7 @@ public class PodUserProfile { isWebUserProfileLoaded = true; } catch (JSONException e) { - Log.d(App.TAG, e.getMessage()); + AppLog.d(this, e.getMessage()); isWebUserProfileLoaded = false; } lastLoaded = System.currentTimeMillis(); diff --git a/app/src/main/java/com/github/dfa/diaspora_android/receivers/OpenExternalLinkReceiver.java b/app/src/main/java/com/github/dfa/diaspora_android/receivers/OpenExternalLinkReceiver.java index 3bc7d492..22f79192 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/receivers/OpenExternalLinkReceiver.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/receivers/OpenExternalLinkReceiver.java @@ -13,6 +13,7 @@ import com.github.dfa.diaspora_android.App; import com.github.dfa.diaspora_android.R; import com.github.dfa.diaspora_android.activity.MainActivity; import com.github.dfa.diaspora_android.data.AppSettings; +import com.github.dfa.diaspora_android.util.AppLog; import com.github.dfa.diaspora_android.util.CustomTabHelpers.BrowserFallback; import com.github.dfa.diaspora_android.util.CustomTabHelpers.CustomTabActivityHelper; import com.github.dfa.diaspora_android.util.Helpers; @@ -33,14 +34,14 @@ public class OpenExternalLinkReceiver extends BroadcastReceiver { public void onReceive(Context c, Intent receiveIntent) { AppSettings settings = new AppSettings(c); - Log.v(App.TAG, "OpenExternalLinkReceiver.onReceive(): url"); + AppLog.v(this, "OpenExternalLinkReceiver.onReceive(): url"); Uri url = null; try { String sUrl = receiveIntent.getStringExtra(MainActivity.EXTRA_URL); url = Uri.parse(sUrl); } catch (Exception _ignored) { - Log.v(App.TAG, "Could not open Chrome Custom Tab (bad URL)"); + AppLog.v(this, "Could not open Chrome Custom Tab (bad URL)"); return; } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/receivers/UpdateTitleReceiver.java b/app/src/main/java/com/github/dfa/diaspora_android/receivers/UpdateTitleReceiver.java index 9a00599b..c722baac 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/receivers/UpdateTitleReceiver.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/receivers/UpdateTitleReceiver.java @@ -8,8 +8,8 @@ import com.github.dfa.diaspora_android.App; import com.github.dfa.diaspora_android.R; import com.github.dfa.diaspora_android.activity.MainActivity; import com.github.dfa.diaspora_android.data.AppSettings; +import com.github.dfa.diaspora_android.util.AppLog; import com.github.dfa.diaspora_android.util.DiasporaUrlHelper; -import com.github.dfa.diaspora_android.util.Log; /** * BroadcastReceiver used to update the title of the MainActivity depending on the url of the webview @@ -17,7 +17,7 @@ import com.github.dfa.diaspora_android.util.Log; */ public class UpdateTitleReceiver extends BroadcastReceiver { private DiasporaUrlHelper urls; - private AppSettings appSettings; + private AppSettings appSettings; private App app; private TitleCallback callback; @@ -33,7 +33,7 @@ public class UpdateTitleReceiver extends BroadcastReceiver { String url = intent.getStringExtra(MainActivity.EXTRA_URL); if (url != null && url.startsWith(urls.getPodUrl())) { String subUrl = url.substring((urls.getPodUrl()).length()); - Log.v(App.TAG, "UpdateTitleReceiver.onReceive(): Set title for subUrl "+subUrl); + AppLog.spam(this, "onReceive()- Set title for subUrl " + subUrl); if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_STREAM)) { setTitle(R.string.nav_stream); } else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_POSTS)) { @@ -56,11 +56,11 @@ public class UpdateTitleReceiver extends BroadcastReceiver { setTitle(R.string.nav_mentions); } else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_PUBLIC)) { setTitle(R.string.public_); - } else if (urls.isAspectUrl(url)){ + } else if (urls.isAspectUrl(url)) { setTitle(urls.getAspectNameFromUrl(url, app)); } } else { - Log.w(App.TAG, "UpdateTitleReceiver.onReceive(): Invalid url: "+url); + AppLog.spam(this, "onReceive()- Invalid url: " + url); } } @@ -74,6 +74,7 @@ public class UpdateTitleReceiver extends BroadcastReceiver { public interface TitleCallback { void setTitle(int Rid); + void setTitle(String title); } } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/task/GetPodsService.java b/app/src/main/java/com/github/dfa/diaspora_android/task/GetPodsService.java index e826c34e..afce5e01 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/task/GetPodsService.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/task/GetPodsService.java @@ -23,9 +23,8 @@ import android.content.Intent; import android.os.AsyncTask; import android.os.IBinder; import android.support.v4.content.LocalBroadcastManager; -import com.github.dfa.diaspora_android.util.Log; -import com.github.dfa.diaspora_android.App; +import com.github.dfa.diaspora_android.util.AppLog; import org.json.JSONArray; import org.json.JSONObject; @@ -43,7 +42,6 @@ import info.guardianproject.netcipher.NetCipher; public class GetPodsService extends Service { public static final String MESSAGE_PODS_RECEIVED = "com.github.dfa.diaspora.podsreceived"; - private static final String TAG = App.TAG; public GetPodsService() { } @@ -92,7 +90,7 @@ public class GetPodsService extends Service { connection.disconnect(); } else { - Log.e(TAG, "Failed to download list of pods"); + AppLog.e(this, "Failed to download list of pods"); } } catch (IOException e) { //TODO handle json buggy feed @@ -102,7 +100,7 @@ public class GetPodsService extends Service { try { JSONObject jsonObjectAll = new JSONObject(builder.toString()); JSONArray jsonArrayAll = jsonObjectAll.getJSONArray("pods"); - Log.d(TAG, "Number of entries " + jsonArrayAll.length()); + AppLog.d(this, "Number of entries " + jsonArrayAll.length()); list = new ArrayList<>(); for (int i = 0; i < jsonArrayAll.length(); i++) { JSONObject jo = jsonArrayAll.getJSONObject(i); diff --git a/app/src/main/java/com/github/dfa/diaspora_android/task/ImageDownloadTask.java b/app/src/main/java/com/github/dfa/diaspora_android/task/ImageDownloadTask.java index 2ebd60df..e9b6677f 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/task/ImageDownloadTask.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/task/ImageDownloadTask.java @@ -22,6 +22,8 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.AsyncTask; import android.support.annotation.Nullable; + +import com.github.dfa.diaspora_android.util.AppLog; import com.github.dfa.diaspora_android.util.Log; import android.widget.ImageView; @@ -78,7 +80,7 @@ public class ImageDownloadTask extends AsyncTask { connection.disconnect(); } catch (Exception e) { - Log.e(App.TAG, e.getMessage()); + AppLog.e(this, e.getMessage()); } finally { try { if (out != null) { diff --git a/app/src/main/java/com/github/dfa/diaspora_android/task/ProfileFetchTask.java b/app/src/main/java/com/github/dfa/diaspora_android/task/ProfileFetchTask.java index 536cbba1..7d4e70e2 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/task/ProfileFetchTask.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/task/ProfileFetchTask.java @@ -20,6 +20,8 @@ package com.github.dfa.diaspora_android.task; import android.content.Context; import android.os.AsyncTask; + +import com.github.dfa.diaspora_android.util.AppLog; import com.github.dfa.diaspora_android.util.Log; import android.webkit.CookieManager; @@ -60,7 +62,7 @@ public class ProfileFetchTask extends AsyncTask { String extractedProfileData = null; final CookieManager cookieManager = app.getCookieManager(); String cookies = cookieManager.getCookie(urls.getPodUrl()); - Log.d(App.TAG, cookies); + AppLog.d(this, cookies); HttpsURLConnection connection; InputStream inStream; @@ -101,7 +103,7 @@ public class ProfileFetchTask extends AsyncTask { if (extractedProfileData != null) { PodUserProfile profile = new PodUserProfile(app); profile.parseJson(extractedProfileData); - Log.d(App.TAG, "Extracted new_messages (service):" + profile.getUnreadMessagesCount()); + AppLog.d(this, "Extracted new_messages (service):" + profile.getUnreadMessagesCount()); } return null; diff --git a/app/src/main/java/com/github/dfa/diaspora_android/task/StatisticsFetchTask.java b/app/src/main/java/com/github/dfa/diaspora_android/task/StatisticsFetchTask.java index 1a94fc17..2a82b609 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/task/StatisticsFetchTask.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/task/StatisticsFetchTask.java @@ -20,6 +20,8 @@ package com.github.dfa.diaspora_android.task; import android.content.Context; import android.os.AsyncTask; + +import com.github.dfa.diaspora_android.util.AppLog; import com.github.dfa.diaspora_android.util.Log; import android.webkit.CookieManager; @@ -77,7 +79,7 @@ public class StatisticsFetchTask extends AsyncTask { BufferedReader br = new BufferedReader(new InputStreamReader(inStream)); String line; while ((line = br.readLine()) != null) { - Log.d(App.TAG, "STATS: "+line); + AppLog.d(this, "STATS: "+line); } try{ diff --git a/app/src/main/java/com/github/dfa/diaspora_android/ui/CustomWebViewClient.java b/app/src/main/java/com/github/dfa/diaspora_android/ui/CustomWebViewClient.java index 9a7832ac..8e31a15c 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/ui/CustomWebViewClient.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/CustomWebViewClient.java @@ -52,13 +52,13 @@ public class CustomWebViewClient extends WebViewClient { final CookieManager cookieManager = app.getCookieManager(); String cookies = cookieManager.getCookie(url); - //Log.d(App.TAG, "All the cookies in a string:" + cookies); + //Log.d(this, "All the cookies in a string:" + cookies); if (cookies != null) { cookieManager.setCookie(url, cookies); cookieManager.setCookie("https://" + app.getSettings().getPodDomain(), cookies); //for (String c : cookies.split(";")) { - // Log.d(App.TAG, "Cookie: " + c.split("=")[0] + " Value:" + c.split("=")[1]); + //AppLog.d(this, "Cookie: " + c.split("=")[0] + " Value:" + c.split("=")[1]); //} //new ProfileFetchTask(app).execute(); } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/util/AppLog.java b/app/src/main/java/com/github/dfa/diaspora_android/util/AppLog.java new file mode 100644 index 00000000..171bbd6c --- /dev/null +++ b/app/src/main/java/com/github/dfa/diaspora_android/util/AppLog.java @@ -0,0 +1,71 @@ +package com.github.dfa.diaspora_android.util; + +/** + * Created by gregor on 18.09.16. + */ +public class AppLog { + private final static String APP_TAG = "d*"; + private static boolean loggingEnabled = true; + private static boolean loggingSpamEnabled = false; + + public static boolean isLoggingEnabled() { + return loggingEnabled; + } + + public static void setLoggingEnabled(boolean loggingEnabled) { + AppLog.loggingEnabled = loggingEnabled; + } + + public static boolean isLoggingSpamEnabled() { + return loggingSpamEnabled; + } + + public static void setLoggingSpamEnabled(boolean loggingSpamEnabled) { + AppLog.loggingSpamEnabled = loggingSpamEnabled; + } + + private static String getLogPrefix(Object source) { + return APP_TAG + "-" + source.getClass().getCanonicalName(); + } + + /* + * + * LOGGER METHODS + * + */ + public static void v(Object source, String _text) { + if (isLoggingEnabled()) { + Log.v(getLogPrefix(source), _text); + } + } + + public static void i(Object source, String _text) { + if (isLoggingEnabled()) { + Log.i(getLogPrefix(source), _text); + } + } + + public static void d(Object source, String _text) { + if (isLoggingEnabled()) { + Log.d(getLogPrefix(source), _text); + } + } + + public static void e(Object source, String _text) { + if (isLoggingEnabled()) { + Log.e(getLogPrefix(source), _text); + } + } + + public static void w(Object source, String _text) { + if (isLoggingEnabled()) { + Log.w(getLogPrefix(source), _text); + } + } + + public static void spam(Object source, String _text) { + if (isLoggingEnabled() && isLoggingSpamEnabled()) { + Log.v(getLogPrefix(source), _text); + } + } +} diff --git a/app/src/main/java/com/github/dfa/diaspora_android/util/CustomTabHelpers/CustomTabsHelper.java b/app/src/main/java/com/github/dfa/diaspora_android/util/CustomTabHelpers/CustomTabsHelper.java index 417c62a7..6ab577af 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/util/CustomTabHelpers/CustomTabsHelper.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/util/CustomTabHelpers/CustomTabsHelper.java @@ -10,6 +10,8 @@ import android.support.customtabs.CustomTabsService; import android.text.TextUtils; import android.util.Log; +import com.github.dfa.diaspora_android.util.AppLog; + import java.util.ArrayList; import java.util.List; @@ -107,7 +109,7 @@ public class CustomTabsHelper { return true; } } catch (RuntimeException e) { - Log.e(TAG, "Runtime exception while getting specialized handlers"); + AppLog.e(TAG, "Runtime exception while getting specialized handlers"); } return false; } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java b/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java index ea8137b4..830380ec 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java @@ -72,7 +72,7 @@ public class Helpers { // Create an image file name String timeStamp = new SimpleDateFormat("dd-MM-yy_HH-mm", Locale.getDefault()).format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; - Log.d(App.TAG, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath()); + AppLog.d(Helpers.class, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath()); File storageDir = Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES); return new File( @@ -116,15 +116,15 @@ public class Helpers { public static void printBundle(Bundle savedInstanceState, String k) { if (savedInstanceState != null) { for (String key : savedInstanceState.keySet()) { - Log.d("SAVED", key + " is a key in the bundle " + k); + AppLog.d("SAVED", key + " is a key in the bundle " + k); Object bun = savedInstanceState.get(key); if (bun != null) { if (bun instanceof Bundle) { printBundle((Bundle) bun, k + "." + key); } else if (bun instanceof byte[]) { - Log.d("SAVED", "Key: " + k + "." + key + ": " + Arrays.toString((byte[]) bun)); + AppLog.d("SAVED", "Key: " + k + "." + key + ": " + Arrays.toString((byte[]) bun)); } else { - Log.d("SAVED", "Key: " + k + "." + key + ": " + bun.toString()); + AppLog.d("SAVED", "Key: " + k + "." + key + ": " + bun.toString()); } } } diff --git a/app/src/main/res/values-cs/strings-preferences.xml b/app/src/main/res/values-cs/strings-preferences.xml index 4ee85f4b..3885ddb3 100644 --- a/app/src/main/res/values-cs/strings-preferences.xml +++ b/app/src/main/res/values-cs/strings-preferences.xml @@ -4,6 +4,7 @@ + @@ -11,6 +12,8 @@ + + diff --git a/app/src/main/res/values-de/strings-about.xml b/app/src/main/res/values-de/strings-about.xml index db5fe69d..c2ffbd61 100644 --- a/app/src/main/res/values-de/strings-about.xml +++ b/app/src/main/res/values-de/strings-about.xml @@ -9,6 +9,7 @@ Gerät Diaspora Pod Debug-Protokoll + Debug-Protokoll (Verbose) App Version: %1$s Paketname: %1$s Android Version: %1$s diff --git a/app/src/main/res/values-de/strings-preferences.xml b/app/src/main/res/values-de/strings-preferences.xml index 6990eb51..ed3586f7 100644 --- a/app/src/main/res/values-de/strings-preferences.xml +++ b/app/src/main/res/values-de/strings-preferences.xml @@ -4,6 +4,7 @@ + Erscheinungsbild Netzwerk @@ -24,6 +25,9 @@ Nutze einen Proxyserver, um Firewalls zu umgehen Host Port + + Chrome Custom Tabs + Externe Links mit Chrome Custom Tabs öffnen. Für dieses Feature muss Chromium oder Google Chrome installiert sein Persönliche Einstellungen Öffne die Einstellungen deines Diaspora Accounts @@ -40,5 +44,6 @@ Werkzeugleisten intelligent verstecken Verweise auf App Füge beim Teilen von Texten einen Verweis auf diese App an (\"geteilt durch…\") + diff --git a/app/src/main/res/values-el/strings-preferences.xml b/app/src/main/res/values-el/strings-preferences.xml index 4ee85f4b..3885ddb3 100644 --- a/app/src/main/res/values-el/strings-preferences.xml +++ b/app/src/main/res/values-el/strings-preferences.xml @@ -4,6 +4,7 @@ + @@ -11,6 +12,8 @@ + + diff --git a/app/src/main/res/values-es/strings-preferences.xml b/app/src/main/res/values-es/strings-preferences.xml index 549c44ac..6a6b67c1 100644 --- a/app/src/main/res/values-es/strings-preferences.xml +++ b/app/src/main/res/values-es/strings-preferences.xml @@ -4,6 +4,7 @@ + Aspecto Red @@ -24,6 +25,7 @@ El tráfico proxificado de Diaspora para evitar firewalls.\nPuede necesitar reiniciarse Anfitrión Puerto + Configuración personal Contactos @@ -39,5 +41,6 @@ Barras de herramientas Intellihide Añadir compartido por aviso Agregar una referencia a esta aplicación (\"compartida por…\") a los textos compartidos + diff --git a/app/src/main/res/values-fr/strings-preferences.xml b/app/src/main/res/values-fr/strings-preferences.xml index 6807c3e2..43b32ccb 100644 --- a/app/src/main/res/values-fr/strings-preferences.xml +++ b/app/src/main/res/values-fr/strings-preferences.xml @@ -4,6 +4,7 @@ + Apparence Paramètres du réseau @@ -24,6 +25,7 @@ Serveur Proxy.\n(Nécessite un redémarrage) Hôte Port + Paramètres personnels Ouvrir vos paramètres de compte diaspora @@ -40,5 +42,6 @@ Masquage intelligent des barres d\'outils Ajoutez \"partagé via …\" aux partages Ajoutez une référence à l\'application (« partagée via …\") aux textes partagés + diff --git a/app/src/main/res/values-hi/strings-preferences.xml b/app/src/main/res/values-hi/strings-preferences.xml index 4ee85f4b..3885ddb3 100644 --- a/app/src/main/res/values-hi/strings-preferences.xml +++ b/app/src/main/res/values-hi/strings-preferences.xml @@ -4,6 +4,7 @@ + @@ -11,6 +12,8 @@ + + diff --git a/app/src/main/res/values-hu/strings-preferences.xml b/app/src/main/res/values-hu/strings-preferences.xml index 4ee85f4b..3885ddb3 100644 --- a/app/src/main/res/values-hu/strings-preferences.xml +++ b/app/src/main/res/values-hu/strings-preferences.xml @@ -4,6 +4,7 @@ + @@ -11,6 +12,8 @@ + + diff --git a/app/src/main/res/values-it/strings-preferences.xml b/app/src/main/res/values-it/strings-preferences.xml index a0a08276..01fbf921 100644 --- a/app/src/main/res/values-it/strings-preferences.xml +++ b/app/src/main/res/values-it/strings-preferences.xml @@ -4,6 +4,7 @@ + Aspetto Rete @@ -24,6 +25,7 @@ Traffico del proxy di Diaspora per bypassare i firewall.\nPuò essere necessario il riavvio dell\'app Host Porta + Impostazioni personali Apri le impostazioni del tuo account Diaspora @@ -40,5 +42,6 @@ Barre che si nascondono intelligentemente Aggiungi avviso dell\'app Aggiunge un riferimento a quest\'app (\"Condiviso da…\") nei testi condivisi + diff --git a/app/src/main/res/values-ja/strings-preferences.xml b/app/src/main/res/values-ja/strings-preferences.xml index fb35504c..bf83e58c 100644 --- a/app/src/main/res/values-ja/strings-preferences.xml +++ b/app/src/main/res/values-ja/strings-preferences.xml @@ -4,6 +4,7 @@ + 外観 ネットワーク @@ -24,6 +25,7 @@ Diaspora の通信をプロキシして、ファイアウォールに回避します。\n再起動が必要になることがあります ホスト ポート + 個人用設定 Diaspora アカウント設定を開きます @@ -40,5 +42,6 @@ Intellihide ツールバー 共有方法の通知を追加 共有テキストに、このアプリへの参照 (\"…で共有\") を追加します + diff --git a/app/src/main/res/values-kn/strings-preferences.xml b/app/src/main/res/values-kn/strings-preferences.xml index 4ee85f4b..3885ddb3 100644 --- a/app/src/main/res/values-kn/strings-preferences.xml +++ b/app/src/main/res/values-kn/strings-preferences.xml @@ -4,6 +4,7 @@ + @@ -11,6 +12,8 @@ + + diff --git a/app/src/main/res/values-ml/strings-preferences.xml b/app/src/main/res/values-ml/strings-preferences.xml index 34886946..390a9139 100644 --- a/app/src/main/res/values-ml/strings-preferences.xml +++ b/app/src/main/res/values-ml/strings-preferences.xml @@ -4,6 +4,7 @@ + കാഴ്ച്ച ശൃങ്കല @@ -24,6 +25,7 @@ ഫയർവാളുകളെ മറികടക്കാൻ ഡയസ്പോറ ട്രാഫിക് പ്രോക്സി ചെയ്യൂ.\nപുനരാരംഭിക്കേണ്ടി വന്നേക്കാം ആഥിതേയൻ പോർട്ട് + സ്വകാര്യ സജ്ജീകരണങ്ങൾ ബന്ധങ്ങൾ @@ -39,5 +41,6 @@ ടൂൾബാറുകൾ ഇന്റലിഹൈഡ് ചെയ്യുക അറിയിപ്പാൽ പങ്കുവച്ചത് എന്ന് കൂട്ടിച്ചേർക്കുക പങ്കുവയ്ക്കുന്ന വാചകങ്ങളിൽ ഈ പ്രയോഗത്തിന്റെ അവലംബം(\"…പങ്കുവച്ചത്\") എന്ന് കൂട്ടിച്ചേർക്കുക + diff --git a/app/src/main/res/values-nl/strings-preferences.xml b/app/src/main/res/values-nl/strings-preferences.xml index cf5d855d..47b807ca 100644 --- a/app/src/main/res/values-nl/strings-preferences.xml +++ b/app/src/main/res/values-nl/strings-preferences.xml @@ -4,6 +4,7 @@ + Vormgeving Netwerk @@ -23,6 +24,7 @@ Gebruik een Proxy voor Diaspora om de firewalls te omzeilen.\nRestart nodig Host Poort + Persoonlijke instellingen Contacten @@ -38,5 +40,6 @@ Werkbalken slim wegwerken Gedeeld-via-aankondiging toevoegen Een verwijzing naar dit app (\"gedeeld door…\") toevoegen aan gedeelde teksten + diff --git a/app/src/main/res/values-no/strings-preferences.xml b/app/src/main/res/values-no/strings-preferences.xml index 4ee85f4b..3885ddb3 100644 --- a/app/src/main/res/values-no/strings-preferences.xml +++ b/app/src/main/res/values-no/strings-preferences.xml @@ -4,6 +4,7 @@ + @@ -11,6 +12,8 @@ + + diff --git a/app/src/main/res/values-pl/strings-preferences.xml b/app/src/main/res/values-pl/strings-preferences.xml index b73241c3..62cae27d 100644 --- a/app/src/main/res/values-pl/strings-preferences.xml +++ b/app/src/main/res/values-pl/strings-preferences.xml @@ -4,6 +4,7 @@ + Wygląd Sieć @@ -17,6 +18,7 @@ Załaduj obrazy Włącz serwer Proxy + Ustawienia osobiste Kontakty @@ -27,5 +29,6 @@ Wyczyść pamięć podręczną Wyczyść pamięć podręczną WebView Automatycznie ukryj paski narzędzi na górze i na dole podczas przewijania + diff --git a/app/src/main/res/values-pt-rBR/strings-preferences.xml b/app/src/main/res/values-pt-rBR/strings-preferences.xml index 15953196..ee8eebc8 100644 --- a/app/src/main/res/values-pt-rBR/strings-preferences.xml +++ b/app/src/main/res/values-pt-rBR/strings-preferences.xml @@ -4,6 +4,7 @@ + Aparência Rede @@ -24,6 +25,7 @@ Usar proxy para o tráfego da diáspora para contornar firewalls.\nPode requerer reinicialização Servidor Porta + Configurações pessoais Contatos @@ -39,5 +41,6 @@ Barras de ferramentas auto ocultante Acrescentar compartilhado-por-aviso Acrescentar uma referência (\"compartilhado por…\") a este app para textos compartilhados + diff --git a/app/src/main/res/values-pt/strings-preferences.xml b/app/src/main/res/values-pt/strings-preferences.xml index 4ee85f4b..3885ddb3 100644 --- a/app/src/main/res/values-pt/strings-preferences.xml +++ b/app/src/main/res/values-pt/strings-preferences.xml @@ -4,6 +4,7 @@ + @@ -11,6 +12,8 @@ + + diff --git a/app/src/main/res/values-ru/strings-preferences.xml b/app/src/main/res/values-ru/strings-preferences.xml index 90ccf613..3bc04e85 100644 --- a/app/src/main/res/values-ru/strings-preferences.xml +++ b/app/src/main/res/values-ru/strings-preferences.xml @@ -4,6 +4,7 @@ + Внешний вид Сеть @@ -24,6 +25,7 @@ Перенаправить трафик Диаспоры в обход брандмауэров.\nМожет потребовать перезапуска Хост Порт + Личные настройки Контакты @@ -39,5 +41,6 @@ Интеллектуальное скрытие панелей инструментов Присоединять \"Опубликовано из\" к сообщению Присоединять ссылку на приложение (\"Опубликовано из…\") к размещенным записям + diff --git a/app/src/main/res/values-sv/strings-preferences.xml b/app/src/main/res/values-sv/strings-preferences.xml index 4ee85f4b..3885ddb3 100644 --- a/app/src/main/res/values-sv/strings-preferences.xml +++ b/app/src/main/res/values-sv/strings-preferences.xml @@ -4,6 +4,7 @@ + @@ -11,6 +12,8 @@ + + diff --git a/app/src/main/res/values-tr/strings-preferences.xml b/app/src/main/res/values-tr/strings-preferences.xml index 4ee85f4b..3885ddb3 100644 --- a/app/src/main/res/values-tr/strings-preferences.xml +++ b/app/src/main/res/values-tr/strings-preferences.xml @@ -4,6 +4,7 @@ + @@ -11,6 +12,8 @@ + + diff --git a/app/src/main/res/values/strings-about.xml b/app/src/main/res/values/strings-about.xml index bdfe895b..38b43ed5 100644 --- a/app/src/main/res/values/strings-about.xml +++ b/app/src/main/res/values/strings-about.xml @@ -14,6 +14,7 @@ Device Diaspora Pod Debug Log + Debug Log (Verbose) App Version: %1$s Package Name: %1$s Android Version: %1$s diff --git a/app/src/main/res/values/strings-preferences.xml b/app/src/main/res/values/strings-preferences.xml index cf1d1fea..9e367342 100644 --- a/app/src/main/res/values/strings-preferences.xml +++ b/app/src/main/res/values/strings-preferences.xml @@ -14,7 +14,7 @@ pref_key_category_network pref_key_load_images pref_key_clear_cache - pref_key__chrome_custom_tabs_enabled + pref_key__chrome_custom_tabs_enabled pref_key_append_shared_via_app pref_key_proxy_enabled @@ -35,7 +35,6 @@ pref_key__visibility_nav__followed_tags pref_key__visibility_nav__profile - podUserProfile_avatar podUserProfile_name @@ -45,11 +44,16 @@ podUserProfile_unreadMessageCount podUserProfile_NotificationCount + + pref_catkey__category_more + pref_key__logging_spam_enabled + pref_key__logging_enabled Appearance Network Pod settings + @string/nav_menu_more @@ -110,5 +114,14 @@ Append shared-by-notice Append a reference to this app ("shared by…") to shared texts + + + @string/about_activity__title_debug_info + @string/fragment_debug__section_log + + @string/fragment_debug__section_log + @string/fragment_debug__section_log_spam + + \ No newline at end of file diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 0caf75e3..6c6308a3 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -141,4 +141,27 @@ android:key="@string/pref_key__proxy_port" android:title="@string/pref_title__proxy_port"/> + + + + + + + + + + + + + \ No newline at end of file