Skip to content

Commit

Permalink
*Infinite scrolling for hot,trending,new tabs
Browse files Browse the repository at this point in the history
*Image loading fixes
*General changes & Improvements
  • Loading branch information
powerpoint45 committed Apr 12, 2019
1 parent 588ecca commit 0717a29
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 141 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
04-12-19
*Infinite scrolling for hot,trending,new tabs
*Image loading fixes
*General changes & Improvements
02-16-19
*Native Video Player support for mobile
*Small UI changes
Expand Down
11 changes: 5 additions & 6 deletions app/AutoUpdate.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<AppUpdater>
<update>
<latestVersion>2.8</latestVersion>
<latestVersionCode>20</latestVersionCode>
<latestVersion>2.83</latestVersion>
<latestVersionCode>23</latestVersionCode>
<url>https://github.com/powerpoint45/dtube-mobile-unofficial/releases</url>
<releaseNotes>
*Native Video Player support for mobile
*Small UI changes
*Gateway fixes
*Bug fixes and general changes
*Infinite scrolling for hot,trending,new tabs
*Image loading fixes
*General changes and Improvements
</releaseNotes>
</update>
</AppUpdater>
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "com.powerpoint45.dtube"
minSdkVersion 21
targetSdkVersion 27
versionCode 22
versionName "2.82"
versionCode 23
versionName "2.83"
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":22,"versionName":"2.82","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":23,"versionName":"2.83","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ public void run() {
((VideoPlayActivity)activity).setSuggestedVideos(videos);
}
});


}

}


Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/powerpoint45/dtube/DtubeAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class DtubeAPI {
static String PROFILE_IMAGE_SMALL_URL = "https://steemitimages.com/u/username/avatar/small";//replace username with actual username
static String PROFILE_IMAGE_MEDIUM_URL = "https://steemitimages.com/u/username/avatar/medium";//replace username with actual username
public String PROFILE_IMAGE_LARGE_URL = "https://steemitimages.com/u/username/avatar/large";//replace username with actual username
static String CONTENT_IMAGE_URL = "https://steemitimages.com/0x0/https://ipfs.io/ipfs/"; // hash at end
//static String CONTENT_IMAGE_URL = "https://steemitimages.com/0x0/https://ipfs.io/ipfs/";
static String CONTENT_IMAGE_URL_BAK = "https://steemitimages.com/0x0/https://ipfs.io/ipfs/"; // hash at end
static String CONTENT_IMAGE_URL = "https://snap1.d.tube/ipfs/";
static String DTUBE_LOGIN_URL = "https://d.tube/#!/login";
static String DTUBE_HOME_URL = "https://d.tube/#!";
static String DTUBE_UPLOAD_URL = "https://d.tube/#!/upload";
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/com/powerpoint45/dtube/FeedAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.github.curioustechizen.ago.RelativeTimeTextView;
import com.google.android.exoplayer2.ExoPlayer;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;

/**
Expand Down Expand Up @@ -139,7 +142,14 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
Picasso.get().load(videos.get(position).getImageURL()).placeholder(placeholderDrawable)
.resize(720,720).centerInside()//prevents image to be shown to be larger than 720px w or h. Makes scrolling smoother
.noFade()
.into(holder.thumbView);
.into(holder.thumbView,new Callback() {
@Override public void onSuccess() {}
@Override public void onError(Exception e) {
Picasso.get().load(videos.get(position).getBackupImageURL()).placeholder(placeholderDrawable)
.resize(720,720).centerInside()//prevents image to be shown to be larger than 720px w or h. Makes scrolling smoother
.noFade()
.into(holder.thumbView);
}});

}

Expand Down
86 changes: 63 additions & 23 deletions app/src/main/java/com/powerpoint45/dtube/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.github.javiersantos.appupdater.AppUpdaterUtils;
import com.github.javiersantos.appupdater.enums.AppUpdaterError;
Expand Down Expand Up @@ -75,8 +76,10 @@ public class MainActivity extends AppCompatActivity {
final int FILES_REQUEST_PERMISSION = 10;

RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;
private FeedAdapter feedAdapter;
LinearLayout bottomBar;
boolean gettingMoreVideos;

SteemitWebView steemWebView;
Toolbar toolbar;
Expand Down Expand Up @@ -305,12 +308,14 @@ public void onDrawerStateChanged(int newState) {
onConfigurationChanged(getResources().getConfiguration());

//Animate toolbar when scrolling feed for non-TV Mode
if (!runningOnTV) {
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
//Enable infinite scrolling
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);

if (!runningOnTV) {
if (toolbar.getHeight() - dy <= 0) {
if (toolbar.getVisibility() == View.VISIBLE)
toolbar.setVisibility(View.GONE);
Expand All @@ -325,10 +330,40 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
else
toolbar.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, toolbar.getHeight() - dy));
}
}

if(((LinearLayoutManager)layoutManager).findLastVisibleItemPosition() == feedAdapter.getItemCount()-1){

if (feedAdapter.getItemCount()>0 && !gettingMoreVideos
&& selectedTab != DtubeAPI.CAT_HISTORY && selectedTab != DtubeAPI.CAT_SUBSCRIBED){
//endless scrolling. Get more videos here
if (getResources().getBoolean(R.bool.debug)) {
Toast.makeText(MainActivity.this, "getting more videos", Toast.LENGTH_SHORT).show();
}

gettingMoreVideos = true;

Video lastVideo = videos.get(videos.size()-1);
switch (selectedTab){
case DtubeAPI.CAT_HOT:
steemWebView.getHotVideosFeed(lastVideo.user,lastVideo.permlink);
break;

case DtubeAPI.CAT_NEW:
steemWebView.getNewVideosFeed(lastVideo.user,lastVideo.permlink);
break;

case DtubeAPI.CAT_TRENDING:
steemWebView.getTrendingVideosFeed(lastVideo.user,lastVideo.permlink);
break;
}
}
}
});
}


}
});


feedAdapter = new FeedAdapter(this, runningOnTV);
recyclerView.setAdapter(feedAdapter);
Expand All @@ -339,9 +374,7 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) {

if (accountInfo!=null)
steemWebView.getSubscriptionFeed(accountInfo.userName);
steemWebView.getHotVideosFeed();
steemWebView.getTrendingVideosFeed();
steemWebView.getNewVideosFeed();
getInitialFeeds();

addVideos(Video.getRecentVideos(this));

Expand Down Expand Up @@ -440,6 +473,8 @@ public boolean addVideos(VideoArrayList videos){


if (allVideos.hasNewContent(videos)) {


for (Video videoToAdd: videos){
if (!allVideos.containsVideo(videoToAdd)){
if (videoToAdd.categoryId == DtubeAPI.CAT_HISTORY)
Expand Down Expand Up @@ -484,19 +519,15 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
steemWebView.getSubscriptions(accountInfo.userName);
if (accountInfo!=null)
steemWebView.getSubscriptionFeed(accountInfo.userName);
steemWebView.getHotVideosFeed();
steemWebView.getTrendingVideosFeed();
steemWebView.getNewVideosFeed();
getInitialFeeds();
break;

case REQUEST_CODE_LOGIN:
setProfileInfoUI();

if (accountInfo!=null)
steemWebView.getSubscriptionFeed(accountInfo.userName);
steemWebView.getHotVideosFeed();
steemWebView.getTrendingVideosFeed();
steemWebView.getNewVideosFeed();
getInitialFeeds();
initFeed();
break;
case REQUEST_CODE_PROFILE:
Expand Down Expand Up @@ -536,6 +567,12 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}

private void getInitialFeeds() {
steemWebView.getHotVideosFeed();
steemWebView.getTrendingVideosFeed();
steemWebView.getNewVideosFeed();
}


@SuppressLint("SetTextI18n")
public void setSubscribers(String account, final int subscribers){
Expand Down Expand Up @@ -622,9 +659,12 @@ public int compare(Video a, Video b)
return Long.compare(b.getDate(), a.getDate());
}
}
synchronized (videos) {
Collections.sort(videos, new SortVideos());
}

if (selectedTab == DtubeAPI.CAT_SUBSCRIBED)
synchronized (videos) {
Collections.sort(videos, new SortVideos());
}

MainActivity.this.runOnUiThread(() -> {
feedAdapter.setVideos(videos);
feedAdapter.notifyDataSetChanged();
Expand Down Expand Up @@ -653,7 +693,7 @@ public int compare(Video a, Video b)
recyclerView.setFocusable(true);
}


gettingMoreVideos = false;
updateBottomBar();
}

Expand Down Expand Up @@ -824,11 +864,11 @@ public void onFailed(AppUpdaterError error) {
@Override
public void onConfigurationChanged(Configuration newConfig) {
if (runningOnTV) {
recyclerView.setLayoutManager(new GridLayoutManager(recyclerView.getContext(), 2, GridLayoutManager.HORIZONTAL, false));
recyclerView.setLayoutManager(layoutManager = new GridLayoutManager(recyclerView.getContext(), 2, GridLayoutManager.HORIZONTAL, false));
}else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
recyclerView.setLayoutManager(layoutManager = new GridLayoutManager(this, 2));
}else
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setLayoutManager(layoutManager = new LinearLayoutManager(this));

//remove cached recycled views because feed_item layout needs to change for orientation
recyclerView.getRecycledViewPool().clear();
Expand Down
20 changes: 17 additions & 3 deletions app/src/main/java/com/powerpoint45/dtube/SteemitWebView.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,32 @@ public void getSubscriptionFeed(String username){
queURL("javascript:getSubscriptionFeed('"+username+"');");
}

public void getHotVideosFeed(String StartAuthor, String StartPermlink){
queURL("javascript:getHotVideosFeed('"+StartAuthor+"','"+StartPermlink+"');");
}


public void getTrendingVideosFeed(String StartAuthor, String StartPermlink){
queURL("javascript:getTrendingVideosFeed('"+StartAuthor+"','"+StartPermlink+"');");
}


public void getNewVideosFeed(String StartAuthor, String StartPermlink){
queURL("javascript:getNewVideosFeed('"+StartAuthor+"','"+StartPermlink+"');");
}

public void getHotVideosFeed(){
queURL("javascript:getHotVideosFeed();");
queURL("javascript:getHotVideosFeed(null,null);");
}


public void getTrendingVideosFeed(){
queURL("javascript:getTrendingVideosFeed();");
queURL("javascript:getTrendingVideosFeed(null,null);");
}


public void getNewVideosFeed(){
queURL("javascript:getNewVideosFeed();");
queURL("javascript:getNewVideosFeed(null,null);");
}


Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/powerpoint45/dtube/Video.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ String getImageURL(){
return DtubeAPI.CONTENT_IMAGE_URL + snapHash;
}

String getBackupImageURL(){
return DtubeAPI.CONTENT_IMAGE_URL_BAK + snapHash;
}


static void removeVideoFromRecents(String permlink, Context c){
VideoArrayList v = getRecentVideos(c);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class VideoArrayList extends ArrayList<Video>{



public int getNumberOfCategories(){
ArrayList<Integer> categories = new ArrayList<>();
for (int i =0; i<size(); i++){
Expand Down
Loading

0 comments on commit 0717a29

Please sign in to comment.