Skip to content

Commit

Permalink
*All nested comments do not load all at once (press view replies on
Browse files Browse the repository at this point in the history
specific comments)
*More efficient fetching requests for steemit content (more efficiency
to come)
*Embedded video player updated from official dtube github
*Fixed app not working due to steemit updates
  • Loading branch information
powerpoint45 committed Jan 23, 2018
1 parent b236c14 commit 9ef0a86
Show file tree
Hide file tree
Showing 26 changed files with 2,205 additions and 741 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
01-23-18
*All nested comments do not load all at once (press view replies on specific comments)
*More efficient fetching requests for steemit content (more efficiency to come)
*Embedded video player updated from official dtube github
*Fixed app not working due to steemit updates
12-8-17
*Video descriptions and comments full support with markdown and autolinking using showdownjs
12-7-17
Expand Down
9 changes: 6 additions & 3 deletions app/AutoUpdate.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<AppUpdater>
<update>
<latestVersion>1.0</latestVersion>
<latestVersionCode>1</latestVersionCode>
<latestVersion>1.1</latestVersion>
<latestVersionCode>2</latestVersionCode>
<url>https://github.com/powerpoint45/dtube-mobile-unofficial/releases</url>
<releaseNotes>
- Initial Release
*All nested comments do not load all at once (press view replies on specific comments)
*More efficient fetching requests for steemit content (more efficiency to come)
*Embedded video player updated from official dtube github
*Fixed app not working due to steemit updates
</releaseNotes>
</update>
</AppUpdater>
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.powerpoint45.dtube"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
versionCode 2
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1},"path":"app-release.apk","properties":{"packageId":"com.powerpoint45.dtube","split":"","minSdkVersion":"19"}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":2},"path":"app-release.apk","properties":{"packageId":"com.powerpoint45.dtube","split":"","minSdkVersion":"19"}}]
73 changes: 53 additions & 20 deletions app/src/main/java/com/powerpoint45/dtube/AppJavaScriptProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,32 +173,29 @@ public void run() {
}

@JavascriptInterface
public void getAllRepliesCallback(String jsonComments){
public void getRepliesCallback(String jsonComments){
try {
JSONArray jarr = new JSONArray(jsonComments);
final CommentsList commentsList = new CommentsList();
for (int i = 0; i<jarr.length(); i++){
JSONObject jo = jarr.getJSONObject(i);
Comment comment = new Comment();
comment.indent = jo.getInt("indent");
comment.permlink = jo.getString("permlink");
comment.likes = jo.getInt("likes");
comment.dislikes = jo.getInt("dislikes");
comment.commentHTML = jo.getString("comment");
//comment.commentHTML = Tools.getFormattedText(comment.commentHTML);
comment.setTime(jo.getString("date"));
comment.voteType = jo.getInt("voteType");
comment.price = jo.getString("price");
comment.userName = jo.getString("author");

commentsList.add(comment);
}
JSONObject jo = new JSONObject(jsonComments);
final Comment comment = new Comment();
comment.indent = jo.getInt("indent");
comment.permlink = jo.getString("permlink");
comment.likes = jo.getInt("likes");
comment.dislikes = jo.getInt("dislikes");
comment.commentHTML = jo.getString("comment");
//comment.commentHTML = Tools.getFormattedText(comment.commentHTML);
comment.setTime(jo.getString("date"));
comment.voteType = jo.getInt("voteType");
comment.price = jo.getString("price");
comment.userName = jo.getString("author");
comment.children = jo.getInt("children");
comment.parent = jo.getString("parent");


if (activity instanceof VideoPlayActivity){
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
((VideoPlayActivity)activity).setReplies(commentsList);
((VideoPlayActivity)activity).addReply(comment);
}
});
}
Expand All @@ -208,6 +205,42 @@ public void run() {
}
}

// @JavascriptInterface
// public void getAllRepliesCallback(String jsonComments){
// try {
// JSONArray jarr = new JSONArray(jsonComments);
// final CommentsList commentsList = new CommentsList();
// for (int i = 0; i<jarr.length(); i++){
// JSONObject jo = jarr.getJSONObject(i);
// Comment comment = new Comment();
// comment.indent = jo.getInt("indent");
// comment.permlink = jo.getString("permlink");
// comment.likes = jo.getInt("likes");
// comment.dislikes = jo.getInt("dislikes");
// comment.commentHTML = jo.getString("comment");
// //comment.commentHTML = Tools.getFormattedText(comment.commentHTML);
// comment.setTime(jo.getString("date"));
// comment.voteType = jo.getInt("voteType");
// comment.price = jo.getString("price");
// comment.userName = jo.getString("author");
//
// commentsList.add(comment);
// }
//
// if (activity instanceof VideoPlayActivity){
// activity.runOnUiThread(new Runnable() {
// @Override
// public void run() {
// ((VideoPlayActivity)activity).setReplies(commentsList);
// }
// });
// }
//
// }catch (JSONException e){
// e.printStackTrace();
// }
// }

@JavascriptInterface
public void getSubscriberCountCallback(String account, final int count){
if (activity instanceof MainActivity)
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/powerpoint45/dtube/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ class Comment implements Serializable {
String price;
int likes;
int dislikes;
int children;

int indent;
String permlink;
String parent;

//0=no vote
//1=vote up
//-1=vote down
int voteType;

CommentsList childComments;

String getImageURL(){
return DtubeAPI.PROFILE_IMAGE_SMALL_URL.replace("username",userName);
}
Expand Down
53 changes: 33 additions & 20 deletions app/src/main/java/com/powerpoint45/dtube/CommentsAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
Expand All @@ -22,19 +23,20 @@
import com.squareup.picasso.Transformation;

import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;

/**
* Created by michael on 9/11/17.
*/

class CommentsAdapter extends BaseAdapter {

private ArrayList<Comment> comments;
private CommentsList comments;
Context c;
private Transformation transformation;
boolean loggedIn;

CommentsAdapter(ArrayList<Comment> comments, Context c, boolean loggedIn){
CommentsAdapter(CommentsList comments, Context c, boolean loggedIn){
this.comments = comments;
this.c = c;
this.loggedIn = loggedIn;
Expand All @@ -45,7 +47,7 @@ class CommentsAdapter extends BaseAdapter {
.build();
}

void setCommentsList(ArrayList<Comment> comments){
void setCommentsList(CommentsList comments){
this.comments = comments;
notifyDataSetChanged();
}
Expand All @@ -65,14 +67,15 @@ private class ViewHolder{
View indentView;
FrameLayout commentReplyHolder;
EditText replyEditText;
Button viewReplies;
}

@Override
public int getCount() {
if(comments == null)
return 0;
else
return comments.size();
return comments.getTotalComments();
}

@Override
Expand All @@ -89,6 +92,8 @@ public long getItemId(int position) {
@Override
public View getView(int position, View v, ViewGroup parent) {

Comment currentComment = comments.getCommentByPosition(position, new AtomicInteger(0));

ViewHolder viewHolder;

if (v!=null && v.getTag()!=null){
Expand All @@ -111,54 +116,62 @@ public View getView(int position, View v, ViewGroup parent) {
viewHolder.replyButton = (TextView) v.findViewById(R.id.comment_reply);
viewHolder.commentReplyHolder = (FrameLayout) v.findViewById(R.id.comment_reply_holder);
viewHolder.replyEditText = (EditText)v.findViewById(R.id.item_comment_reply_edittext);
viewHolder.viewReplies = (Button)v.findViewById(R.id.view_replies);
}

if (!(viewHolder.likeView.getTag()!=null && comments.get(position).permlink!=null && viewHolder.likeView.getTag().equals(comments.get(position).permlink))){
if (!(viewHolder.likeView.getTag()!=null && currentComment.permlink!=null && viewHolder.likeView.getTag().equals(currentComment.permlink))){
Spanned result;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
result = Html.fromHtml(comments.get(position).commentHTML, Html.FROM_HTML_MODE_LEGACY);
result = Html.fromHtml(currentComment.commentHTML, Html.FROM_HTML_MODE_LEGACY);
} else {
result = Html.fromHtml(comments.get(position).commentHTML);
result = Html.fromHtml(currentComment.commentHTML);
}
viewHolder.commentView.setText(result);
viewHolder.commentView.setMovementMethod(LinkMovementMethod.getInstance());
viewHolder.usernameView.setText(comments.get(position).userName);
viewHolder.dateView.setReferenceTime(comments.get(position).getDate());
if (comments.get(position).indent>0)
viewHolder.usernameView.setText(currentComment.userName);
viewHolder.dateView.setReferenceTime(currentComment.getDate());
if (currentComment.indent>0)
viewHolder.indentView.setVisibility(View.VISIBLE);
else
viewHolder.indentView.setVisibility(View.GONE);

Picasso.with(c).load(comments.get(position).getImageURL()).placeholder(R.drawable.ic_account_circle).transform(transformation)
Picasso.with(c).load(currentComment.getImageURL()).placeholder(R.drawable.ic_account_circle).transform(transformation)
.into(viewHolder.profileView);
}

viewHolder.commentReplyHolder.setVisibility(View.GONE);
viewHolder.replyEditText.setOnEditorActionListener(null);
viewHolder.replyEditText.setOnKeyListener(null);

if (currentComment.children>0 && currentComment.childComments==null){
viewHolder.viewReplies.setVisibility(View.VISIBLE);
}else if (currentComment.childComments!=null){
viewHolder.viewReplies.setVisibility(View.GONE);
}else {
viewHolder.viewReplies.setVisibility(View.GONE);
}


viewHolder.priceView.setText(comments.get(position).price);
viewHolder.likesView.setText(""+comments.get(position).likes);
viewHolder.dislikesView.setText(""+comments.get(position).dislikes);
viewHolder.priceView.setText(currentComment.price);
viewHolder.likesView.setText(""+currentComment.likes);
viewHolder.dislikesView.setText(""+currentComment.dislikes);

viewHolder.likeView.setColorFilter(null);
viewHolder.dislikeView.setColorFilter(null);

viewHolder.likeView.setTag(comments.get(position).permlink);
viewHolder.dislikeView.setTag(comments.get(position).permlink);
viewHolder.replyButton.setTag(comments.get(position).permlink);
viewHolder.replyButton.setTag(currentComment.permlink);
viewHolder.likeView.setTag(currentComment.permlink);
viewHolder.dislikeView.setTag(currentComment.permlink);
viewHolder.viewReplies.setTag(currentComment.permlink);

if (!loggedIn) {
viewHolder.replyButton.setEnabled(false);
viewHolder.likeView.setEnabled(false);
viewHolder.dislikeView.setEnabled(false);
}

if (comments.get(position).voteType == 1){
if (currentComment.voteType == 1){
viewHolder.likeView.setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
}else if(comments.get(position).voteType == -1)
}else if(currentComment.voteType == -1)
viewHolder.dislikeView.setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);


Expand Down
53 changes: 53 additions & 0 deletions app/src/main/java/com/powerpoint45/dtube/CommentsList.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.powerpoint45.dtube;

import android.util.Log;

import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;

/**
* Created by michael on 9/11/17.
Expand All @@ -18,11 +21,61 @@ public boolean contains(Comment comment){

public Comment getCommentByID(String id){
for (Comment c: this){

if (c.permlink.equals(id))
return c;

if (c.childComments!=null)
if (c.childComments.getCommentByID(id)!=null)
return c.childComments.getCommentByID(id);

}

return null;
}

public int getTotalComments(){
int numberOfComments = 0;
for (Comment c: this){
numberOfComments ++;
if (c.childComments!=null)
numberOfComments+=c.childComments.getTotalComments();
}

return numberOfComments;
}

//AtomicInteger is used to find comment by position since in java you can't pass integer by reference
public Comment getCommentByPosition(int pos, AtomicInteger currentIndex){
for (int i =0; i<size(); i++){
if (currentIndex.get() == pos) {
Log.d("DT","R:"+currentIndex.get()+","+get(i).commentHTML);
return get(i);
}

currentIndex.set(currentIndex.get()+1);

if (get(i).childComments!=null){
Comment nestedComment = get(i).childComments.getCommentByPosition(pos,currentIndex);
if (nestedComment!=null) {
Log.d("DT","C:"+currentIndex.get()+","+nestedComment.commentHTML);
return nestedComment;
}
}
}
return null;
}


public int getCommentPosition(String id){
int totalComments = getTotalComments();
AtomicInteger atomicInteger = new AtomicInteger(0);
for (int i =0; i<totalComments; i++){
if (getCommentByPosition(i, atomicInteger).permlink.equals(id))
return i;
}

return 0;
}

}
6 changes: 5 additions & 1 deletion app/src/main/java/com/powerpoint45/dtube/SteemitWebView.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ public void getVideoInfo(String author, String permlink, String accountName){
}

public void getReplies(String author, String permlink, String accountName){
queURL("javascript:getAllReplies('"+author+"','"+permlink+"','"+accountName+"');");
queURL("javascript:getReplies('"+author+"','"+permlink+"','"+accountName+"');");
}

// public void getAllReplies(String author, String permlink, String accountName){
// queURL("javascript:getAllReplies('"+author+"','"+permlink+"','"+accountName+"');");
// }

public void getChannelVideos(String author, String lastPermlink){
queURL("javascript:getAuthorVideos('"+author+"','"+lastPermlink+"');");
}
Expand Down
Loading

0 comments on commit 9ef0a86

Please sign in to comment.