aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java21
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java18
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/User/ParseUserData.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/User/UserData.java31
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java2
5 files changed, 72 insertions, 8 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java
index b793ad8b..a00bf56d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java
@@ -149,6 +149,9 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
@Named("post_layout")
SharedPreferences mPostLayoutSharedPreferences;
@Inject
+ @Named("nsfw_and_spoiler")
+ SharedPreferences mNsfwAndSpoilerSharedPreferences;
+ @Inject
CustomThemeWrapper mCustomThemeWrapper;
public UserViewModel userViewModel;
private FragmentManager fragmentManager;
@@ -179,6 +182,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
private String mMessageFullname;
private String mNewAccountName;
private SlidrInterface mSlidrInterface;
+ private MaterialAlertDialogBuilder nsfwWarningBuilder;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -417,7 +421,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
if (!title.equals(userFullName)) {
getSupportActionBar().setTitle(userFullName);
}
- String karma = getString(R.string.karma_info_user_detail, userData.getKarma(), userData.getLinkKarma(), userData.getCommentKarma());
+ String karma = getString(R.string.karma_info_user_detail, userData.getTotalKarma(), userData.getLinkKarma(), userData.getCommentKarma());
karmaTextView.setText(karma);
cakedayTextView.setText(getString(R.string.cakeday_info, new SimpleDateFormat("MMM d, yyyy",
locale).format(userData.getCakeday())));
@@ -428,6 +432,21 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
descriptionTextView.setVisibility(View.VISIBLE);
descriptionTextView.setText(userData.getDescription());
}
+
+ if (userData.isNSFW()) {
+ if (nsfwWarningBuilder == null
+ && !mNsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.NSFW_BASE, false)) {
+ nsfwWarningBuilder = new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
+ .setTitle(R.string.warning)
+ .setMessage(R.string.this_user_has_nsfw_content)
+ .setPositiveButton(R.string.leave, (dialogInterface, i)
+ -> {
+ finish();
+ })
+ .setNegativeButton(R.string.dismiss, null);
+ nsfwWarningBuilder.show();
+ }
+ }
}
});
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java
index 2556a173..18ce485d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java
@@ -28,7 +28,7 @@ import ml.docilealligator.infinityforreddit.User.UserDao;
import ml.docilealligator.infinityforreddit.User.UserData;
@Database(entities = {Account.class, SubredditData.class, SubscribedSubredditData.class, UserData.class,
- SubscribedUserData.class, MultiReddit.class, CustomTheme.class, RecentSearchQuery.class}, version = 10)
+ SubscribedUserData.class, MultiReddit.class, CustomTheme.class, RecentSearchQuery.class}, version = 11)
public abstract class RedditDataRoomDatabase extends RoomDatabase {
private static RedditDataRoomDatabase INSTANCE;
@@ -40,7 +40,7 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
RedditDataRoomDatabase.class, "reddit_data")
.addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5,
MIGRATION_5_6, MIGRATION_6_7, MIGRATION_7_8, MIGRATION_8_9,
- MIGRATION_9_10)
+ MIGRATION_9_10, MIGRATION_10_11)
.build();
}
}
@@ -229,4 +229,18 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
+ " ADD COLUMN over18 INTEGER DEFAULT 0 NOT NULL");
}
};
+
+ private static final Migration MIGRATION_10_11 = new Migration(10, 11) {
+ @Override
+ public void migrate(@NonNull SupportSQLiteDatabase database) {
+ database.execSQL("ALTER TABLE users"
+ + " ADD COLUMN awarder_karma INTEGER DEFAULT 0 NOT NULL");
+ database.execSQL("ALTER TABLE users"
+ + " ADD COLUMN awardee_karma INTEGER DEFAULT 0 NOT NULL");
+ database.execSQL("ALTER TABLE users"
+ + " ADD COLUMN total_karma INTEGER DEFAULT 0 NOT NULL");
+ database.execSQL("ALTER TABLE users"
+ + " ADD COLUMN over_18 INTEGER DEFAULT 0 NOT NULL");
+ }
+ };
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/User/ParseUserData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/User/ParseUserData.java
index 65e32933..e640d7e3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/User/ParseUserData.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/User/ParseUserData.java
@@ -37,13 +37,17 @@ public class ParseUserData {
}
int linkKarma = userDataJson.getInt(JSONUtils.LINK_KARMA_KEY);
int commentKarma = userDataJson.getInt(JSONUtils.COMMENT_KARMA_KEY);
+ int awarderKarma = userDataJson.getInt(JSONUtils.AWARDER_KARMA_KEY);
+ int awardeeKarma = userDataJson.getInt(JSONUtils.AWARDEE_KARMA_KEY);
+ int totalKarma = userDataJson.getInt(JSONUtils.TOTAL_KARMA_KEY);
long cakeday = userDataJson.getLong(JSONUtils.CREATED_UTC_KEY) * 1000;
boolean isGold = userDataJson.getBoolean(JSONUtils.IS_GOLD_KEY);
boolean isFriend = userDataJson.getBoolean(JSONUtils.IS_FRIEND_KEY);
+ boolean isNsfw = userDataJson.getJSONObject(JSONUtils.SUBREDDIT_KEY).getBoolean(JSONUtils.OVER_18_KEY);
String description = userDataJson.getJSONObject(JSONUtils.SUBREDDIT_KEY).getString(JSONUtils.PUBLIC_DESCRIPTION_KEY);
- return new UserData(userName, iconImageUrl, bannerImageUrl, linkKarma, commentKarma, cakeday,
- isGold, isFriend, canBeFollowed, description);
+ return new UserData(userName, iconImageUrl, bannerImageUrl, linkKarma, commentKarma, awarderKarma,
+ awardeeKarma, totalKarma, cakeday, isGold, isFriend, canBeFollowed, isNsfw, description);
}
interface ParseUserDataListener {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/User/UserData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/User/UserData.java
index 8ad00b49..2e4243c7 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/User/UserData.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/User/UserData.java
@@ -19,6 +19,12 @@ public class UserData {
private int linkKarma;
@ColumnInfo(name = "comment_karma")
private int commentKarma;
+ @ColumnInfo(name = "awarder_karma")
+ private int awarderKarma;
+ @ColumnInfo(name = "awardee_karma")
+ private int awardeeKarma;
+ @ColumnInfo(name = "total_karma")
+ private int totalKarma;
@ColumnInfo(name = "created_utc")
private long cakeday;
@ColumnInfo(name = "is_gold")
@@ -27,20 +33,27 @@ public class UserData {
private boolean isFriend;
@ColumnInfo(name = "can_be_followed")
private boolean canBeFollowed;
+ @ColumnInfo(name = "over_18")
+ private boolean isNSFW;
@ColumnInfo(name = "description")
private String description;
public UserData(@NonNull String name, String iconUrl, String banner, int linkKarma, int commentKarma,
- long cakeday, boolean isGold, boolean isFriend, boolean canBeFollowed, String description) {
+ int awarderKarma, int awardeeKarma, int totalKarma, long cakeday, boolean isGold,
+ boolean isFriend, boolean canBeFollowed, boolean isNSFW, String description) {
this.name = name;
this.iconUrl = iconUrl;
this.banner = banner;
this.commentKarma = commentKarma;
this.linkKarma = linkKarma;
+ this.awarderKarma = awarderKarma;
+ this.awarderKarma = awardeeKarma;
+ this.totalKarma = totalKarma;
this.cakeday = cakeday;
this.isGold = isGold;
this.isFriend = isFriend;
this.canBeFollowed = canBeFollowed;
+ this.isNSFW = isNSFW;
this.description = description;
}
@@ -65,8 +78,16 @@ public class UserData {
return commentKarma;
}
- public int getKarma() {
- return linkKarma + commentKarma;
+ public int getAwarderKarma() {
+ return awarderKarma;
+ }
+
+ public int getAwardeeKarma() {
+ return awardeeKarma;
+ }
+
+ public int getTotalKarma() {
+ return totalKarma;
}
public long getCakeday() {
@@ -85,6 +106,10 @@ public class UserData {
return canBeFollowed;
}
+ public boolean isNSFW() {
+ return isNSFW;
+ }
+
public String getDescription() {
return description;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java
index 50c8e0bd..2b1ff97b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java
@@ -128,4 +128,6 @@ public class JSONUtils {
public static final String SUGGESTED_COMMENT_SORT_KEY = "suggested_comment_sort";
public static final String OVER18_KEY = "over18";
public static final String TOTAL_KARMA_KEY = "total_karma";
+ public static final String AWARDER_KARMA_KEY = "awarder_karma";
+ public static final String AWARDEE_KARMA_KEY = "awardee_karma";
}