Skip to content

Commit

Permalink
Completely remove channel view counts
Browse files Browse the repository at this point in the history
  • Loading branch information
samfundev committed Jan 25, 2025
1 parent 7649c4d commit b280027
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public void channelInfo() throws MalformedURLException {
new UserInfo("1", "login", "name"),
"description",
2,
3,
new URL("https://example.com/logo"),
new URL("https://example.com/videoBanner"),
new URL("https://example.com/profileBanner")
Expand All @@ -47,7 +46,6 @@ public void channelInfo() throws MalformedURLException {
ChannelInfo newChannelInfo = clone(channelInfo);

assertEquals(channelInfo.getStreamDescription(), newChannelInfo.getStreamDescription());
assertEquals(channelInfo.getViews(), newChannelInfo.getViews());
assertEquals(channelInfo.getLogoURL(), newChannelInfo.getLogoURL());
assertEquals(channelInfo.getVideoBannerURL(), newChannelInfo.getVideoBannerURL());
assertEquals(channelInfo.getProfileBannerURL(), newChannelInfo.getProfileBannerURL());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1370,18 +1370,16 @@ private void setupProfileBottomSheet() {

TextView mNameView = mProfileBottomSheet.findViewById(R.id.twitch_name);
TextView mFollowers = mProfileBottomSheet.findViewById(R.id.txt_followers);
TextView mViewers = mProfileBottomSheet.findViewById(R.id.txt_viewers);
ImageView mFollowButton = mProfileBottomSheet.findViewById(R.id.follow_unfollow_icon);
ImageView mFullProfileButton = mProfileBottomSheet.findViewById(R.id.full_profile_icon);
RecyclerView mPanelsRecyclerView = mProfileBottomSheet.findViewById(R.id.panel_recyclerview);
if (mNameView == null || mFollowers == null || mViewers == null || mFullProfileButton == null || mPanelsRecyclerView == null)
if (mNameView == null || mFollowers == null || mFullProfileButton == null || mPanelsRecyclerView == null)
return;

mNameView.setText(mUserInfo.getDisplayName());

Execute.background(() -> Service.getStreamerInfoFromUserId(mUserInfo.getUserId(), getContext()), channelInfo -> {
channelInfo.getFollowers(getContext(), followers -> Utils.setNumber(mFollowers, followers), 0);
Utils.setNumber(mViewers, channelInfo.getViews());

setupFollowButton(mFollowButton, channelInfo);
});
Expand Down
22 changes: 7 additions & 15 deletions app/src/main/java/com/perflyst/twire/model/ChannelInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@ public class ChannelInfo extends UserInfo implements Comparable<ChannelInfo>, Pa
public static final Parcelable.Creator<ChannelInfo> CREATOR = new ClassLoaderCreator<ChannelInfo>() {
@Override
public ChannelInfo createFromParcel(Parcel source) {
String[] data = new String[9];
String[] data = new String[8];

source.readStringArray(data);
return new ChannelInfo(
new UserInfo(data[0], data[1], data[2]),
data[3],
Integer.parseInt(data[4]),
Integer.parseInt(data[5]),
findUrl(data[5]),
findUrl(data[6]),
findUrl(data[7]),
findUrl(data[8])
findUrl(data[7])
);
}

Expand All @@ -65,18 +64,16 @@ public URL findUrl(String text) {
}
};
@Nullable private Integer followers;
private final int views;
private String streamDescription;
private URL logoURL;
private URL videoBannerURL;
private URL profileBannerURL;
private boolean notifyWhenLive;

public ChannelInfo(UserInfo userInfo, String streamDescription, int followers, int views, URL logoURL, URL videoBannerURL, URL profileBannerURL) {
public ChannelInfo(UserInfo userInfo, String streamDescription, int followers, URL logoURL, URL videoBannerURL, URL profileBannerURL) {
super(userInfo.getUserId(), userInfo.getLogin(), userInfo.getDisplayName());
this.streamDescription = streamDescription;
this.followers = followers == -1 ? null : followers;
this.views = views;
this.logoURL = logoURL;
this.videoBannerURL = videoBannerURL;
this.profileBannerURL = profileBannerURL;
Expand All @@ -97,23 +94,22 @@ public void writeToParcel(@NonNull Parcel dest, int flags) {
this.getDisplayName(),
this.streamDescription,
String.valueOf(Objects.requireNonNullElse(this.followers, -1)),
String.valueOf(this.views),
null, //this.logoURL.toString(),
null, //this.videoBannerURL.toString(),
null, //this.profileBannerURL.toString()
};

// Only send URLS with if they are not null
if (this.logoURL != null) {
toSend[6] = String.valueOf(this.logoURL);
toSend[5] = String.valueOf(this.logoURL);
}

if (this.videoBannerURL != null) {
toSend[7] = String.valueOf(this.videoBannerURL);
toSend[6] = String.valueOf(this.videoBannerURL);
}

if (this.profileBannerURL != null) {
toSend[8] = String.valueOf(this.profileBannerURL);
toSend[7] = String.valueOf(this.profileBannerURL);
}

dest.writeStringArray(toSend);
Expand Down Expand Up @@ -174,10 +170,6 @@ public Integer fetchFollowers(Context context) {
}
}

public int getViews() {
return views;
}

public URL getVideoBannerURL() {
return videoBannerURL;
}
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/com/perflyst/twire/service/JSONService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public class JSONService {
public static int getVodLength(String length) {
int all = 0;
String[] letters = {
"h",
"m",
"s"
"h",
"m",
"s"
};
int[] times = {
3600,
Expand All @@ -41,7 +41,7 @@ public static int getVodLength(String length) {
"[0-9]+[s]"
};

for (int i=0; i < regex.length; i++) {
for (int i = 0; i < regex.length; i++) {
Pattern pattern = Pattern.compile(regex[i]);
Matcher matcher = pattern.matcher(length);
if (matcher.find()) {
Expand Down Expand Up @@ -104,7 +104,7 @@ public static StreamInfo getStreamInfo(Context context, JSONObject streamObject,

String gameName = streamObject.getString(GAME_STRING);

String title = context.getString(R.string.default_stream_title, userInfo.getDisplayName(), gameName);
String title = context.getString(R.string.default_stream_title, userInfo.getDisplayName(), gameName);
int currentViewers = streamObject.getInt(CURRENT_VIEWERS_INT);

if (streamObject.has(CHANNEL_STATUS_STRING)) {
Expand Down Expand Up @@ -154,7 +154,7 @@ public static ChannelInfo getStreamerInfo(Context context, JSONObject channel) t
profileBannerURL = new URL(channel.getString(PROFILE_BANNER_URL_STRING));
}

final ChannelInfo channelInfo = new ChannelInfo(userInfo, "", -1, views, logoURL, videoBannerURL, profileBannerURL);
final ChannelInfo channelInfo = new ChannelInfo(userInfo, "", -1, logoURL, videoBannerURL, profileBannerURL);

channelInfo.setStreamDescription(channel.getString(BIO_STRING));

Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/com/perflyst/twire/service/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ public static ChannelInfo getStreamerInfoFromUserId(String streamerId, Context c
int views = info.getInt("view_count");
String description = info.getString("description");

channelInfo = new ChannelInfo(JSONService.getUserInfo(info), description, -1, views, logoURL, videoBannerURL, profileBannerURL);
channelInfo = new ChannelInfo(JSONService.getUserInfo(info), description, -1, logoURL, videoBannerURL, profileBannerURL);

} catch (JSONException e) {
Timber.v(e);
Expand Down Expand Up @@ -586,7 +586,6 @@ public static Map<String, ChannelInfo> getStreamerInfoFromDB(Context context) {
String displayName = cursor.getString(2);
String streamDescription = cursor.getString(3);
int followers = cursor.getInt(4);
int views = cursor.getInt(5);
URL logo = null;
URL videoBanner = null;
URL profileBanner = null;
Expand All @@ -610,7 +609,7 @@ public static Map<String, ChannelInfo> getStreamerInfoFromDB(Context context) {

// Create new StreamerInfo object from data fetched from database
ChannelInfo mChannelInfo = new ChannelInfo(new UserInfo(streamerId, streamerName, displayName),
streamDescription, followers, views, logo, videoBanner, profileBanner);
streamDescription, followers, logo, videoBanner, profileBanner);
mChannelInfo.setNotifyWhenLive(notifyWhenLive);
subscriptions.put(mChannelInfo.getDisplayName(), mChannelInfo);

Expand Down Expand Up @@ -710,7 +709,7 @@ public static void insertStreamerInfoToDB(Context context, ChannelInfo streamer)
values.put(SubscriptionsDbHelper.COLUMN_STREAMER_NAME, streamer.getLogin());
values.put(SubscriptionsDbHelper.COLUMN_DISPLAY_NAME, streamer.getDisplayName());
values.put(SubscriptionsDbHelper.COLUMN_DESCRIPTION, streamer.getStreamDescription());
values.put(SubscriptionsDbHelper.COLUMN_UNIQUE_VIEWS, streamer.getViews());
values.put(SubscriptionsDbHelper.COLUMN_UNIQUE_VIEWS, 0);
values.put(SubscriptionsDbHelper.COLUMN_NOTIFY_WHEN_LIVE, disableForStreamer ? 0 : 1); // Enable by default
values.put(SubscriptionsDbHelper.COLUMN_IS_TWITCH_FOLLOW, 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public int onImport(SQLiteDatabase db) {
values.put(SubscriptionsDbHelper.COLUMN_DISPLAY_NAME, tempchannel.getString("DISPLAY_NAME"));
values.put(SubscriptionsDbHelper.COLUMN_DESCRIPTION, tempchannel.getString("DESCRIPTION"));
values.put(SubscriptionsDbHelper.COLUMN_FOLLOWERS, tempchannel.getInt("FOLLOWERS"));
values.put(SubscriptionsDbHelper.COLUMN_UNIQUE_VIEWS, tempchannel.getInt("VIEWS"));
values.put(SubscriptionsDbHelper.COLUMN_NOTIFY_WHEN_LIVE, tempchannel.getInt("NOTIFY"));
values.put(SubscriptionsDbHelper.COLUMN_IS_TWITCH_FOLLOW, tempchannel.getInt("IS_TWITCH"));

Expand All @@ -161,9 +160,9 @@ public int onImport(SQLiteDatabase db) {

// check what methode should be used
String sql = "SELECT * FROM " + SubscriptionsDbHelper.TABLE_NAME + " WHERE _ID=" + tempchannel.getInt("ID");
Cursor cursor = db.rawQuery(sql,null);
Cursor cursor = db.rawQuery(sql, null);

if (cursor.getCount()>0) {
if (cursor.getCount() > 0) {
db.replace(SubscriptionsDbHelper.TABLE_NAME, null, values);
} else {
db.insert(SubscriptionsDbHelper.TABLE_NAME, null, values);
Expand All @@ -189,7 +188,6 @@ public int onExport(SQLiteDatabase db) {
int displayNamePosition = cursor.getColumnIndex(SubscriptionsDbHelper.COLUMN_DISPLAY_NAME);
int bioPosition = cursor.getColumnIndex(SubscriptionsDbHelper.COLUMN_DESCRIPTION);
int followersPosition = cursor.getColumnIndex(SubscriptionsDbHelper.COLUMN_FOLLOWERS);
int viewsPosition = cursor.getColumnIndex(SubscriptionsDbHelper.COLUMN_UNIQUE_VIEWS);
int logoPosition = cursor.getColumnIndex(SubscriptionsDbHelper.COLUMN_LOGO_URL);
int bannerPosition = cursor.getColumnIndex(SubscriptionsDbHelper.COLUMN_VIDEO_BANNER_URL);
int banner_profilePosition = cursor.getColumnIndex(SubscriptionsDbHelper.COLUMN_PROFILE_BANNER_URL);
Expand All @@ -201,7 +199,6 @@ public int onExport(SQLiteDatabase db) {
String displayname = cursor.getString(displayNamePosition);
String description = cursor.getString(bioPosition);
int followers = cursor.getInt(followersPosition);
int views = cursor.getInt(viewsPosition);
String logo = cursor.getString(logoPosition);
String banner = cursor.getString(bannerPosition);
String profilebanner = cursor.getString(banner_profilePosition);
Expand All @@ -215,7 +212,6 @@ public int onExport(SQLiteDatabase db) {
tempchannel.put("DISPLAY_NAME", displayname);
tempchannel.put("DESCRIPTION", description);
tempchannel.put("FOLLOWERS", followers);
tempchannel.put("VIEWS", views);
tempchannel.put("LOGO", logo);
tempchannel.put("BANNER", banner);
tempchannel.put("PROFILE_BANNER", profilebanner);
Expand All @@ -228,7 +224,7 @@ public int onExport(SQLiteDatabase db) {
}
cursor.close();

if (channelstoExport.length()>0) {
if (channelstoExport.length() > 0) {
try {
JSONObject channels = new JSONObject();
channels.put("Channels", channelstoExport);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public void run() {
values.put(SubscriptionsDbHelper.COLUMN_DISPLAY_NAME, subToAdd.getDisplayName());
values.put(SubscriptionsDbHelper.COLUMN_DESCRIPTION, subToAdd.getStreamDescription());
values.put(SubscriptionsDbHelper.COLUMN_FOLLOWERS, Objects.requireNonNullElse(subToAdd.fetchFollowers(baseContext), 0));
values.put(SubscriptionsDbHelper.COLUMN_UNIQUE_VIEWS, subToAdd.getViews());
values.put(SubscriptionsDbHelper.COLUMN_NOTIFY_WHEN_LIVE, subToAdd.isNotifyWhenLive() && !disableForStreamer ? 1 : 0);
values.put(SubscriptionsDbHelper.COLUMN_IS_TWITCH_FOLLOW, 1);

Expand Down
74 changes: 16 additions & 58 deletions app/src/main/res/layout/stream_profile_preview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,64 +63,22 @@
android:orientation="horizontal"
android:padding="@dimen/streamerInfo_additional_info_padding">

<FrameLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">

<TextView
android:id="@+id/txt_followers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textAppearance="@style/text_streamer_info"
android:textSize="@dimen/streamerInfo_followers_size" />

<ImageView
android:layout_width="@dimen/streamerInfo_additional_info_icon_size"
android:layout_height="@dimen/streamerInfo_additional_info_icon_size"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/streamerInfo_stat_icons_padding"
android:layout_marginRight="@dimen/streamerInfo_stat_icons_padding"
android:src="@drawable/ic_person"
app:tint="@color/white" />
</LinearLayout>
</FrameLayout>

<FrameLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">

<TextView
android:id="@+id/txt_viewers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/text_streamer_info"
android:textSize="@dimen/streamerInfo_views_size" />

<ImageView
android:layout_width="@dimen/streamerInfo_additional_info_icon_size"
android:layout_height="@dimen/streamerInfo_additional_info_icon_size"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/streamerInfo_stat_icons_padding"
android:layout_marginRight="@dimen/streamerInfo_stat_icons_padding"
android:src="@drawable/ic_visibility"
app:tint="@color/white" />
</LinearLayout>
</FrameLayout>
<TextView
android:id="@+id/txt_followers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textAppearance="@style/text_streamer_info"
android:textSize="@dimen/streamerInfo_followers_size" />

<ImageView
android:layout_width="@dimen/streamerInfo_additional_info_icon_size"
android:layout_height="@dimen/streamerInfo_additional_info_icon_size"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/streamerInfo_stat_icons_padding"
android:layout_marginRight="@dimen/streamerInfo_stat_icons_padding"
android:src="@drawable/ic_person"
app:tint="@color/white" />
</LinearLayout>

</RelativeLayout>
Expand Down

0 comments on commit b280027

Please sign in to comment.