Skip to content

Commit

Permalink
start using fabric for bug reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed Dec 29, 2015
1 parent 70dce6f commit 5e31c1f
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 57 deletions.
17 changes: 15 additions & 2 deletions twidere/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}

dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
import fr.avianey.androidsvgdrawable.gradle.SvgDrawableTask

import java.text.SimpleDateFormat

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'androidsvgdrawable'

Expand Down Expand Up @@ -52,6 +62,7 @@ android {

repositories {
maven { url 'https://s3.amazonaws.com/repo.commonsware.com' }
maven { url 'https://maven.fabric.io/public' }
flatDir { dirs "$projectDir/lib" }
}

Expand Down Expand Up @@ -88,13 +99,12 @@ dependencies {
compile 'org.apache.commons:commons-lang3:3.4'
compile 'commons-primitives:commons-primitives:1.0'
compile 'com.bluelinelabs:logansquare:1.3.4'
compile 'ch.acra:acra:4.7.0'
compile 'org.jraf:android-switch-backport:2.0.1'
compile 'com.github.FasterXML:jackson-jr-trees:5baf62567e'
compile 'com.makeramen:roundedimageview:2.1.1'
compile 'com.soundcloud.android:android-crop:1.0.1@aar'
compile 'com.hannesdorfmann.parcelableplease:annotation:1.0.1'
compile 'com.github.mariotaku:PickNCrop:1dff3ed574'
compile 'com.github.mariotaku:PickNCrop:6c9d888a9d'
compile 'com.github.mariotaku.RestFu:library:0.9.8'
compile 'com.github.mariotaku.RestFu:okhttp:0.9.8'
compile 'com.diogobernardino:williamchart:2.1'
Expand All @@ -114,6 +124,9 @@ dependencies {
compile fileTree(dir: 'libs/main', include: ['*.jar'])
provided 'javax.annotation:jsr250-api:1.0'
// googleCompile fileTree(dir: 'libs/google', include: ['*.jar'])
compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
transitive = true;
}
}

task svgToDrawable(type: SvgDrawableTask) {
Expand Down
4 changes: 4 additions & 0 deletions twidere/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
android:name="com.sec.android.app.multiwindow"
android:required="false"/>

<meta-data
android:name="io.fabric.ApiKey"
android:value="dc4ee756d3b705e00011782f1426fc8656ad3bd9" />

<meta-data
android:name="com.google.android.backup.api_key"
android:value="AEdPqrEAAAAIKbKATV1AGbLB4kem3w8QaPVJSPVVumbMHxkfwA"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.view.MarginLayoutParamsCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.WindowCompat;
import android.view.View;
import android.view.WindowManager;

Expand Down Expand Up @@ -61,11 +63,11 @@ public void onContentChanged() {
}

@Override
public void onCreate(final Bundle icicle) {
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
super.onCreate(icicle);
final int themeColor = getThemeColor();
final int themeResId = getCurrentThemeResourceId();
final String backgroundOption = getCurrentThemeBackgroundOption();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1114,9 +1114,8 @@ private void setMenu() {
* Has media & Not reply: [Take photo][Media menu][Attach location][Drafts]
* Is reply: [Media menu][View status][Attach location][Drafts]
*/
MenuUtils.setMenuItemAvailability(menu, R.id.take_photo, hasInReplyTo);
MenuUtils.setMenuItemAvailability(menu, R.id.add_image, !hasMedia && !hasInReplyTo);
MenuUtils.setMenuItemAvailability(menu, R.id.media_menu, hasMedia || hasInReplyTo);
MenuUtils.setMenuItemAvailability(menu, R.id.add_image, !hasMedia);
MenuUtils.setMenuItemAvailability(menu, R.id.media_menu, hasMedia);
MenuUtils.setMenuItemAvailability(menu, R.id.toggle_sensitive, hasMedia);
MenuUtils.setMenuItemAvailability(menu, R.id.link_to_quoted_status, isQuote());
MenuUtils.setMenuItemAvailability(menu, R.id.schedule, isScheduleSupported());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,11 @@ protected void onStart() {
@Override
protected void onResume() {
super.onResume();
if (ThemeUtils.isDarkTheme(getCurrentThemeResourceId())) {
// TODO show dark bar
} else {
ActivitySupport.setTaskDescription(this, new TaskDescriptionCompat(null, null, getThemeColor()));
}
sendBroadcast(new Intent(BROADCAST_HOME_ACTIVITY_ONRESUME));
invalidateOptionsMenu();
updateActionsButtonStyle();
Expand Down Expand Up @@ -794,7 +799,6 @@ private void setupBars() {
mTabIndicator.setStripColor(contrastColor);
mTabIndicator.setIconColor(contrastColor);
mTabIndicator.setLabelColor(contrastColor);
ActivitySupport.setTaskDescription(this, new TaskDescriptionCompat(null, null, themeColor));
}
mHomeContent.setDrawColor(true);
mHomeContent.setDrawShadow(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ protected void onCreate(final Bundle savedInstanceState) {
}
mMainContent.setOnFitSystemWindowsListener(this);
setStatusBarColor(linkId, data);
setTaskInfo(linkId, data);
Utils.logOpenNotificationFromUri(this, data);
if (!showFragment(linkId, data)) {
finish();
Expand Down Expand Up @@ -395,21 +394,6 @@ private void setStatusBarColor(int linkId, Uri uri) {
StatusBarProxy.setStatusBarDarkIcon(getWindow(), TwidereColorUtils.getYIQLuminance(statusBarColor) > ThemeUtils.ACCENT_COLOR_THRESHOLD);
}

private void setTaskInfo(int linkId, Uri uri) {
switch (linkId) {
// case LINK_ID_USER: {
// break;
// }
default: {
if (ThemeUtils.isColoredActionBar(getCurrentThemeResourceId())) {
ActivitySupport.setTaskDescription(this, new TaskDescriptionCompat(null, null,
getCurrentThemeColor()));
}
break;
}
}
}

private boolean showFragment(final int linkId, final Uri uri) {
final Intent intent = getIntent();
intent.setExtrasClassLoader(getClassLoader());
Expand Down Expand Up @@ -589,6 +573,15 @@ public int getControlBarHeight() {
return mActionBarHeight = ThemeUtils.getActionBarHeight(this);
}

@Override
protected void onResume() {
super.onResume();
if (ThemeUtils.isColoredActionBar(getCurrentThemeResourceId())) {
ActivitySupport.setTaskDescription(this, new TaskDescriptionCompat(null, null,
getCurrentThemeColor()));
}
}

public ActionBarContainer getActionBarContainer() {
return mActionBarContainer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiskCache;
import com.squareup.okhttp.Dns;

import org.acra.annotation.ReportsCrashes;
import org.apache.commons.lang3.ArrayUtils;
import org.mariotaku.twidere.BuildConfig;
import org.mariotaku.twidere.Constants;
Expand Down Expand Up @@ -67,9 +66,6 @@
import static org.mariotaku.twidere.util.Utils.initAccountColor;
import static org.mariotaku.twidere.util.Utils.startRefreshServiceIfNeeded;

@ReportsCrashes(formUri = "https://twidere-bugreport.herokuapp.com/reports",
buildConfigClass = BuildConfig.class, sendReportsInDevMode = false,
sendReportsAtShutdown = false)
public class TwidereApplication extends MultiDexApplication implements Constants,
OnSharedPreferenceChangeListener {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ public boolean hasRunningTasksForTag(final String tag) {
return false;
}

public void cancel(final String tag) {
for (final ManagedAsyncTask<?, ?, ?> task : getTaskSpecList()) {
if (tag.equals(task.getTag())) {
task.cancel(true);
}
}
}

public boolean isExecuting(final int hashCode) {
final ManagedAsyncTask<?, ?, ?> task = findTask(hashCode);
return task != null && task.getStatus() == AsyncTask.Status.RUNNING;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
package org.mariotaku.twidere.util;

import android.app.Application;
import android.os.AsyncTask;
import android.support.annotation.Nullable;
import android.util.Log;

import org.acra.ACRA;
import com.crashlytics.android.Crashlytics;

import org.mariotaku.twidere.BuildConfig;
import org.mariotaku.twidere.Constants;

import io.fabric.sdk.android.Fabric;

/**
* Created by mariotaku on 15/7/8.
*/
Expand Down Expand Up @@ -58,28 +60,12 @@ protected void errorImpl(@Nullable String message, @Nullable Throwable throwable
}

private void handleSilentException(final Throwable throwable) {
AsyncTask.execute(new Runnable() {
@Override
public void run() {
ACRA.getErrorReporter().handleSilentException(throwable);
}
});
Crashlytics.logException(throwable);
}

@Override
protected void initImpl(final Application application) {
// ACRA sets it self as DefaultUncaughtExceptionHandler, we hijack it to suppress some errors
ACRA.init(application);
// handler should be ACRA's ErrorReporter now
final Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
// We can't fix OOM, so just don't report it and try to save VM
if (Utils.isOutOfMemory(ex)) return;
handler.uncaughtException(thread, ex);
}
});
Fabric.with(application, new Crashlytics());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
import android.support.annotation.WorkerThread;
import android.text.TextUtils;
import android.webkit.URLUtil;
Expand Down Expand Up @@ -144,11 +143,12 @@ public static void updateHttpClientConfiguration(final SharedPreferences prefs,
final boolean enableProxy = prefs.getBoolean(KEY_ENABLE_PROXY, false);

client.setConnectTimeout(connectionTimeout, TimeUnit.SECONDS);
final long connectionTimeoutMillis = TimeUnit.MILLISECONDS.convert(connectionTimeout, TimeUnit.SECONDS);
client.setReadTimeout(0, TimeUnit.SECONDS);
client.setWriteTimeout(0, TimeUnit.SECONDS);
final SSLSocketFactory sslSocketFactory;
if (ignoreSslError) {
// We intentionally use insecure connections
sslSocketFactory = SSLCertificateSocketFactory.getInsecure((int) connectionTimeoutMillis, null);
sslSocketFactory = SSLCertificateSocketFactory.getInsecure(0, null);
if (sslSocketFactory instanceof SSLCertificateSocketFactory) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public int loadVideo(String uri, VideoLoadingListener listener) {

public int loadVideo(String uri, boolean forceReload, VideoLoadingListener listener) {
if (mTaskManager.hasRunningTasksForTag(uri)) {
return 0;
if (!forceReload) return 0;
mTaskManager.cancel(uri);
}
return mTaskManager.add(new PreLoadVideoTask(mContext, this, listener, uri, forceReload), true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private InetAddress[] fromResolver(String originalHost, String host, int depth)
for (final Record record : records) {
if (record instanceof CNAMERecord)
return resolveInternal(originalHost, ((CNAMERecord) record).getTarget().toString(),
+1);
depth + 1);
}
return null;
}
Expand Down
1 change: 1 addition & 0 deletions twidere/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@
<string name="report_usage_statistics_now">Report usage statistics now</string>
<string name="cache_size_limit">Cache size limit</string>
<string name="bug_reports">Bug reports</string>
<string name="bug_reports_summary">Powered by Fabric</string>
<string name="invalid_consumer_key">Invalid consumer key</string>
<string name="invalid_consumer_secret">Invalid consumer secret</string>
<string name="page_up">Page up</string>
Expand Down
9 changes: 5 additions & 4 deletions twidere/src/main/res/xml/preferences_usage_statistics.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

<Preference android:layout="@layout/header_usage_statistics" />
<Preference android:layout="@layout/header_usage_statistics"/>

<org.mariotaku.twidere.preference.AutoFixCheckBoxPreference
android:defaultValue="false"
android:key="usage_statistics"
android:order="11"
android:title="@string/usage_statistics" />
android:title="@string/usage_statistics"/>

<org.mariotaku.twidere.preference.AutoFixCheckBoxPreference
android:defaultValue="true"
android:key="bug_reports"
android:order="12"
android:title="@string/bug_reports" />
android:summary="@string/bug_reports_summary"
android:title="@string/bug_reports"/>

<PreferenceCategory
android:order="13"
Expand All @@ -40,7 +41,7 @@
<Preference android:title="@string/research_hot_mobile">
<intent
android:action="android.intent.action.VIEW"
android:data="http://spice.hot-mobile.org/" />
android:data="http://spice.hot-mobile.org/"/>
</Preference>
</PreferenceCategory>

Expand Down

0 comments on commit 5e31c1f

Please sign in to comment.