Skip to content

Commit 7c254b2

Browse files
bxutesinghpratyush
authored andcommitted
Add explore tab, refactor hashtags display logic, code refactoring and fix event reporting mechanism (#229)
1 parent 54e2a78 commit 7c254b2

34 files changed

+481
-358
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ android {
3737
applicationId "com.hapramp"
3838
minSdkVersion 16
3939
targetSdkVersion 27
40-
versionCode 62
41-
versionName "0.0.16"
40+
versionCode 65
41+
versionName "0.0.18"
4242
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
4343
multiDexEnabled true
4444
}

app/src/main/java/com/hapramp/analytics/EventReporter.java

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
import java.util.ArrayList;
1414

1515
public class EventReporter {
16-
static ArrayList<String> events = new ArrayList<>();
17-
static String open_time;
18-
static String close_time;
19-
2016
public static void reportOpenEvent() {
2117
String date = MomentsUtils.getDate();
2218
String time = MomentsUtils.getCurrentTime();
@@ -42,37 +38,12 @@ public static String getAppVersion(Context context) {
4238
}
4339

4440
public static void reportEventSession(Context context) {
45-
StringBuilder stringBuilder = new StringBuilder();
46-
for (int i = 0; i < events.size(); i++) {
47-
stringBuilder.append(events.get(i))
48-
.append(" > ");
49-
}
50-
close_time = MomentsUtils.getCurrentTime();
51-
EventReportModel eventReportModel = new EventReportModel(open_time,
52-
close_time,
53-
stringBuilder.toString());
54-
String username = HaprampPreferenceManager.getInstance().getCurrentSteemUsername();
55-
if (username.length() > 0) {
56-
EventReportUtils.getEventReportNodeRef(
57-
getAppVersion(context),
58-
MomentsUtils.getDate(),
59-
username,
60-
close_time
61-
).setValue(eventReportModel).addOnSuccessListener(new OnSuccessListener<Void>() {
62-
@Override
63-
public void onSuccess(Void aVoid) {
64-
events.clear();
65-
}
66-
});
67-
}
6841
}
6942

7043
public static void setOpenTime() {
71-
open_time = MomentsUtils.getCurrentTime();
7244
}
7345

7446
public static void addEvent(String event) {
75-
events.add(event);
7647
}
7748

7849
public static void reportDeviceId() {

app/src/main/java/com/hapramp/datastore/DataDispatcher.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ public void run() {
109109
}
110110
}
111111

112+
void dispatchExplorePosts(String response, final boolean isFreshData, final boolean isAppendable,
113+
final UserFeedCallback userFeedCallback){
114+
final List<Feed> feeds = jsonParser.parseExplorePosts(response);
115+
if (userFeedCallback != null) {
116+
handler.post(new Runnable() {
117+
@Override
118+
public void run() {
119+
userFeedCallback.onUserFeedsAvailable(feeds, isFreshData, isAppendable);
120+
}
121+
});
122+
}
123+
}
124+
112125
void dispatchCommunityFeed(String response, final boolean isFreshData, final boolean isAppendable,
113126
final UserFeedCallback userFeedCallback) {
114127
final List<Feed> feeds = jsonParser.parseCuratedFeed(response);
@@ -474,4 +487,5 @@ public void run() {
474487
});
475488
}
476489
}
490+
477491
}

app/src/main/java/com/hapramp/datastore/DataStore.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.hapramp.datastore.callbacks.FollowInfoCallback;
88
import com.hapramp.datastore.callbacks.FollowersCallback;
99
import com.hapramp.datastore.callbacks.FollowingsCallback;
10-
import com.hapramp.datastore.callbacks.ResourceCreditCallback;
1110
import com.hapramp.datastore.callbacks.RewardFundMedianPriceCallback;
1211
import com.hapramp.datastore.callbacks.SinglePostCallback;
1312
import com.hapramp.datastore.callbacks.TransferHistoryCallback;
@@ -749,6 +748,13 @@ public void run() {
749748
}.start();
750749
}
751750

751+
/**
752+
* Fetches single post from steemit api.
753+
*
754+
* @param author author of post/feed
755+
* @param permlink permlink of post/feed
756+
* @param singlePostCallback callback for returning response
757+
*/
752758
public void requestSingleFeed(final String author, final String permlink, final SinglePostCallback singlePostCallback) {
753759
new Thread() {
754760
@Override
@@ -771,5 +777,38 @@ public void run() {
771777
}.start();
772778
}
773779

780+
public void requestExploreFeeds(final UserFeedCallback userFeedCallback) {
781+
if (userFeedCallback != null) {
782+
userFeedCallback.onFeedsFetching();
783+
}
784+
final String rtag = "user_explore_feeds_initial";
785+
this.currentFeedRequestTag = rtag;
786+
new Thread() {
787+
@Override
788+
public void run() {
789+
String url = URLS.explorePostsUrl();
790+
String cachedResponse = DataCache.get(url);
791+
if (cachedResponse != null) {
792+
dispatchExplorePosts(cachedResponse, false, false, userFeedCallback);
793+
}
794+
try {
795+
Response response = NetworkApi.getNetworkApiInstance().fetch(url);
796+
if (response.isSuccessful()) {
797+
String res = response.body().string();
798+
DataCache.cache(url, res);
799+
if (isFeedRequestLive(rtag)) {
800+
dispatchExplorePosts(res, true, false, userFeedCallback);
801+
}
802+
} else {
803+
dispatchUserFeedsError("Error Code:" + response.code(), userFeedCallback);
804+
}
805+
}
806+
catch (IOException e) {
807+
dispatchUserFeedsError("IOException " + e.toString(), userFeedCallback);
808+
}
809+
}
810+
}.start();
811+
}
812+
774813
}
775814

app/src/main/java/com/hapramp/datastore/JSONParser.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,21 @@ public ArrayList<Feed> parseUserFeed(String response) {
8585
return feeds;
8686
}
8787

88+
public ArrayList<Feed> parseExplorePosts(String response) {
89+
ArrayList<Feed> feeds = new ArrayList<>();
90+
try {
91+
JSONArray jsonArray = new JSONArray(response);
92+
for (int i = 0; i < jsonArray.length(); i++) {
93+
JSONObject co = jsonArray.getJSONObject(i);
94+
feeds.add(parseCoreFeedData(co));
95+
}
96+
}
97+
catch (JSONException e) {
98+
99+
}
100+
return feeds;
101+
}
102+
88103
private Feed parseCoreFeedData(JSONObject rootObject) {
89104
Feed feed = new Feed();
90105
try {

app/src/main/java/com/hapramp/datastore/URLS.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ public class URLS {
66
private static final String STEEMIT_API_URL = "https://api.steemit.com";
77
private static final String STEEMIT_URL = "https://steemit.com/";
88

9-
public static String singlePostFetchUrl(String category, String author, String permlink) {
10-
String _category = category.length() > 0 ? category + "/" : "";
11-
return String.format("%s%s@%s/%s.json", STEEMIT_URL, _category, author, permlink);
9+
public static String explorePostsUrl() {
10+
return BASE_URL +
11+
"feeds/all";
1212
}
1313

1414
public static String steemUrl() {

app/src/main/java/com/hapramp/models/CommunityModel.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public CommunityModel(String mDescription, String mImageUri, String mTag, String
2525
this.mId = mId;
2626
}
2727

28+
public CommunityModel( String mColor, String mName) {
29+
this.mColor = mColor;
30+
this.mName = mName;
31+
}
32+
2833
public String getmDescription() {
2934
return mDescription;
3035
}

app/src/main/java/com/hapramp/steem/Communities.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
package com.hapramp.steem;
22

3-
import com.google.gson.Gson;
4-
import com.hapramp.models.CommunityModel;
5-
import com.hapramp.preferences.HaprampPreferenceManager;
6-
7-
import java.util.List;
8-
93
public class Communities {
104
public static final String ALL = "all";
5+
public static final String EXPLORE = "explore";
116
public static final String TAG_HAPRAMP = "hapramp";
12-
public static final String IMAGE_URI_ALL = "https://user-images.githubusercontent.com/10809719/39564005-05b3a8cc-4ed0-11e8-8854-4714ef346798.png";
7+
public static final String[] supportedCommunities = {
8+
"art",
9+
"dance",
10+
"travel",
11+
"literature",
12+
"film",
13+
"photography",
14+
"fashion",
15+
"design"};
1316

1417
public static boolean doesCommunityExists(String community_tag) {
15-
String json = HaprampPreferenceManager.getInstance().getAllCommunityAsJson();
16-
if (json.length() > 0) {
17-
CommunityListWrapper communityListWrapper = new Gson().fromJson(json, CommunityListWrapper.class);
18-
if (communityListWrapper != null) {
19-
List<CommunityModel> communities = communityListWrapper.getCommunityModels();
20-
for (int i = 0; i < communities.size(); i++) {
21-
if (communities.get(i).getmTag().equals(community_tag)) {
22-
return true;
23-
}
24-
}
18+
for (int i = 0; i < supportedCommunities.length; i++) {
19+
if (community_tag.toLowerCase().equals(supportedCommunities[i])) {
20+
return true;
2521
}
2622
}
2723
return false;

app/src/main/java/com/hapramp/steem/LocalConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
public class LocalConfig {
88
public static final String PARENT_PERMALINK = "hapramp";
9-
public static final String APP_TAG = "1ramp/0.0.16";
9+
public static final String APP_TAG = "1ramp/0.0.18";
1010
}

app/src/main/java/com/hapramp/ui/activity/CreateArticleActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ private void publishArticle() {
151151
title = articleTitleEt.getText().toString().trim();
152152
generated_permalink = PermlinkGenerator.getPermlink(title);
153153
tags = (ArrayList<String>) articleCategoryView.getSelectedTags();
154-
tags = PostHashTagPreprocessor.processHashtags(tags);
155154
includeCustomTags(tags);
155+
tags = PostHashTagPreprocessor.processHashtags(tags);
156156
body = markDEditor.getMarkdownContent();
157157
images = getImageLinks();
158158
if (validArticle()) {

0 commit comments

Comments
 (0)