Skip to content

Commit

Permalink
Add Sentry
Browse files Browse the repository at this point in the history
Fixes #207
  • Loading branch information
samfundev committed Jul 6, 2024
1 parent 5c0a2b2 commit ba7a821
Show file tree
Hide file tree
Showing 29 changed files with 123 additions and 48 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'com.android.application'
id "io.sentry.android.gradle" version "4.7.1"
}

android {
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
android:name="com.sec.android.multiwindow.MINIMUM_SIZE_H"
android:value="598.0dip" />

<!-- Sentry -->
<meta-data android:name="io.sentry.dsn" android:value="https://[email protected]/1" />
<meta-data
android:name="io.sentry.auto-init"
android:value="false" />

<activity
android:name=".activities.stream.LiveStreamActivity"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/com/perflyst/twire/TwireApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,33 @@
import com.techyourchance.threadposter.BackgroundThreadPoster;
import com.techyourchance.threadposter.UiThreadPoster;

import java.util.HashMap;

import io.sentry.android.core.SentryAndroid;

/**
* Created by SebastianRask on 20-02-2016.
*/
public class TwireApplication extends Application {
public static final UiThreadPoster uiThreadPoster = new UiThreadPoster();
public static final BackgroundThreadPoster backgroundPoster = new BackgroundThreadPoster();

@Override
public void onCreate() {
super.onCreate();

SentryAndroid.init(this, options -> {
options.setBeforeSend((event, hint) -> {
event.setUser(null);
event.getContexts().remove("device");
event.getContexts().put("device", new HashMap<String, String>() {
{
put("model", android.os.Build.MODEL);
}
});
event.setEnvironment(BuildConfig.BUILD_TYPE);
return event;
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.util.List;
import java.util.regex.Matcher;

import io.sentry.Sentry;

public class DeepLinkActivity extends AppCompatActivity {
private int errorMessage = R.string.router_unknown_error;

Expand All @@ -49,7 +51,7 @@ public void onCreate(Bundle savedInstance) {
try {
intent = getNewIntent(params, paramSize);
} catch (Exception exception) {
exception.printStackTrace();
Sentry.captureException(exception);
}

if (intent == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import com.perflyst.twire.views.recyclerviews.AutoSpanRecyclerView;
import com.perflyst.twire.views.recyclerviews.auto_span_behaviours.AutoSpanBehaviour;

import io.sentry.Sentry;


public abstract class MainActivity<E extends Comparable<E> & MainElement> extends ThemeActivity {
private static final String FIRST_VISIBLE_ELEMENT_POSITION = "firstVisibleElementPosition";
Expand Down Expand Up @@ -469,7 +471,7 @@ public void onAnimationEnd(Animation animation) {
MainActivity.super.onBackPressed();
overridePendingTransition(0, 0);
} catch (IllegalStateException e) {
e.printStackTrace();
Sentry.captureException(e);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import io.codetail.animation.SupportAnimator;
import io.codetail.animation.ViewAnimationUtils;
import io.sentry.Sentry;

public class ConfirmSetupActivity extends SetupBaseActivity {
private final int REVEAL_ANIMATION_DURATION = 650;
Expand Down Expand Up @@ -244,7 +245,7 @@ protected Void doInBackground(Void... params) {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
Sentry.captureException(e);
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import java.util.List;
import java.util.Set;

import io.sentry.Sentry;

public abstract class StreamActivity extends ThemeActivity implements StreamFragment.StreamFragmentListener {
private final String LOG_TAG = getClass().getSimpleName();
public StreamFragment mStreamFragment;
Expand Down Expand Up @@ -126,7 +128,7 @@ public void onBackPressed() {
try {
mStreamFragment.backPressed();
} catch (NullPointerException e) {
e.printStackTrace();
Sentry.captureException(e);
}
this.overrideTransition();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import java.util.List;
import java.util.regex.Matcher;

import io.sentry.Sentry;

/**
* Created by SebastianRask on 03-03-2016.
*/
Expand Down Expand Up @@ -139,7 +141,7 @@ public void onBindViewHolder(@NonNull final ContactViewHolder holder, int positi
} catch (Exception e) {
//In case twitch doesn't comply to their own API.
Log.d(LOG_TAG, "Failed to show Message");
e.printStackTrace();
Sentry.captureException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.ArrayList;
import java.util.List;

import io.sentry.Sentry;

/**
* Created by Sebastian Rask on 24-02-2017.
*/
Expand Down Expand Up @@ -75,7 +77,7 @@ public void onBindViewHolder(@NonNull final PanelViewHolder holder, int position
mTabs.build().launchUrl(mActivity, Uri.parse(link));

} catch (ActivityNotFoundException e) {
e.printStackTrace();
Sentry.captureException(e);
}
});
}
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/java/com/perflyst/twire/chat/ChatEmoteManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import io.sentry.Sentry;

/**
* Created by sebastian on 26/07/2017.
*/
Expand Down Expand Up @@ -95,7 +97,7 @@ void loadCustomEmotes(EmoteFetchCallback callback) {
}
}
} catch (JSONException e) {
e.printStackTrace();
Sentry.captureException(e);
}

// FFZ emotes
Expand Down Expand Up @@ -148,7 +150,7 @@ void loadCustomEmotes(EmoteFetchCallback callback) {
}
}
} catch (JSONException e) {
e.printStackTrace();
Sentry.captureException(e);
}

// 7TV emotes
Expand Down Expand Up @@ -192,13 +194,13 @@ void loadCustomEmotes(EmoteFetchCallback callback) {
}
}
} catch (JSONException e) {
e.printStackTrace();
Sentry.captureException(e);
}

try {
callback.onEmoteFetched();
} catch (Exception e) {
e.printStackTrace();
Sentry.captureException(e);
}
}

Expand Down
14 changes: 8 additions & 6 deletions app/src/main/java/com/perflyst/twire/chat/ChatManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

import javax.net.ssl.SSLSocketFactory;

import io.sentry.Sentry;

public class ChatManager implements Runnable {
public static ChatManager instance = null;

Expand Down Expand Up @@ -247,7 +249,7 @@ private void connect(String address, int port) {
// If we reach this line then the socket closed but chat wasn't stopped, so reconnect.
if (!isStopping) connect(address, port);
} catch (IOException e) {
e.printStackTrace();
Sentry.captureException(e);

onUpdate(UpdateType.ON_CONNECTION_FAILED);
SystemClock.sleep(2500);
Expand Down Expand Up @@ -407,7 +409,7 @@ private void processVodChat() {
downloadedComments.poll();
}
} catch (Exception e) {
e.printStackTrace();
Sentry.captureException(e);

onUpdate(UpdateType.ON_CONNECTION_FAILED);
SystemClock.sleep(2500);
Expand Down Expand Up @@ -567,7 +569,7 @@ private void sendRawMessage(String message) {
writer.write(message + " \r\n");
writer.flush();
} catch (IOException e) {
e.printStackTrace();
Sentry.captureException(e);
}
}

Expand All @@ -594,7 +596,7 @@ public void sendMessage(final String message) {
writer.flush();
}
} catch (Exception e) {
e.printStackTrace();
Sentry.captureException(e);
}
}

Expand Down Expand Up @@ -627,7 +629,7 @@ private void readBadges(String url, Map<String, Map<String, Badge>> badgeMap) {
}
}
} catch (JSONException e) {
e.printStackTrace();
Sentry.captureException(e);
}
}

Expand Down Expand Up @@ -657,7 +659,7 @@ private void readFFZBadges() {

ffzBadgeMap = mapBuilder.build();
} catch (JSONException e) {
e.printStackTrace();
Sentry.captureException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import io.sentry.Sentry;


interface EmoteKeyboardDelegate {
void onEmoteClicked(Emote clickedEmote, View view);
Expand Down Expand Up @@ -272,7 +274,7 @@ public void onCustomEmoteIdFetched(List<Emote> channel, List<Emote> global) {
customEmoteInfoLoaded(channel, global);
}
} catch (IllegalAccessError e) {
e.printStackTrace();
Sentry.captureException(e);
}
}

Expand Down Expand Up @@ -790,7 +792,7 @@ public void onGlobalLayout() {
lastBottom = r.bottom;
}
} catch (IllegalStateException e) {
e.printStackTrace();
Sentry.captureException(e);
}
}
});
Expand All @@ -817,7 +819,7 @@ private void sendMessage() {
addMessage(chatMessage);
Log.d(LOG_TAG, "Message added");
} catch (Exception e) {
e.printStackTrace();
Sentry.captureException(e);
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;

import io.sentry.Sentry;

@OptIn(markerClass = UnstableApi.class)
public class StreamFragment extends Fragment implements Player.Listener {
private static final int SHOW_TIMEOUT = 3000;
Expand Down Expand Up @@ -699,7 +701,7 @@ public void run() {

Utils.setNumber(mCurrentViewersView, currentViewers);
} catch (Exception e) {
e.printStackTrace();
Sentry.captureException(e);
}
}, mUserInfo.getUserId(), getContext()
);
Expand Down Expand Up @@ -1187,7 +1189,7 @@ private void startStreamWithTask() {
playbackFailed();
}
} catch (IllegalStateException | NullPointerException e) {
e.printStackTrace();
Sentry.captureException(e);
}
};

Expand All @@ -1214,7 +1216,7 @@ private void updateQualitySelectorsWithTask() {
qualityURLs = url;
}
} catch (IllegalStateException | NullPointerException e) {
e.printStackTrace();
Sentry.captureException(e);
}
};

Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/com/perflyst/twire/model/ChannelInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.net.URL;
import java.util.Objects;

import io.sentry.Sentry;

/**
* Created by Sebastian Rask on 30-01-2015.
* This class is designed to hold all relevant information about a twitch user/streamer
Expand Down Expand Up @@ -59,7 +61,7 @@ public URL findUrl(String text) {
try {
return new URL(text);
} catch (MalformedURLException e) {
e.printStackTrace();
Sentry.captureException(e);
return null;
}
}
Expand Down Expand Up @@ -172,7 +174,7 @@ public Integer fetchFollowers(Context context) {
followers = fullDataObject.getInt("total");
return followers;
} catch (JSONException e) {
e.printStackTrace();
Sentry.captureException(e);
return null;
}
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/perflyst/twire/model/SleepTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.perflyst.twire.service.DialogService;
import com.perflyst.twire.service.Settings;

import io.sentry.Sentry;

/**
* Created by Sebastian Rask Jepsen on 22/07/16.
*/
Expand Down Expand Up @@ -42,7 +44,7 @@ public void run() {
sleepTimerHandler.postDelayed(this, 1000 * 60);
}
} catch (Exception e) {
e.printStackTrace();
Sentry.captureException(e);
Log.e(LOG_TAG, "Sleep Timer runnable failed");
}
}
Expand Down
Loading

0 comments on commit ba7a821

Please sign in to comment.