Skip to content

Commit

Permalink
Merge pull request #22 from swesust/development/foysal
Browse files Browse the repository at this point in the history
Development/foysal
  • Loading branch information
rafiulgits authored Apr 26, 2020
2 parents ffa19ce + 0b84c3d commit 2bade82
Show file tree
Hide file tree
Showing 24 changed files with 638 additions and 29 deletions.
2 changes: 2 additions & 0 deletions Covid19Shahajjo/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ dependencies {
implementation 'com.google.code.gson:gson:2.4'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google.firebase:firebase-analytics:17.2.2'
implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:10.0.3'

}
11 changes: 11 additions & 0 deletions Covid19Shahajjo/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@
<activity android:name=".activities.HelpCenterMapActivity" />
<activity android:name=".activities.ContactSupportActivity" />

<activity android:name=".activities.YoutubeFullScreenActivity"
android:configChanges="orientation"
android:screenOrientation="landscape"
android:theme="@style/youtubeFullScreenTheme">

</activity>
<activity android:name=".activities.Covid19StoryActivity"
android:screenOrientation="portrait">

</activity>

<receiver
android:name=".services.ConnectivityReceiver"
android:enabled="true">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.example.covid19shahajjo.activities;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.covid19shahajjo.R;
import com.example.covid19shahajjo.models.YouTubeVideos;
import com.example.covid19shahajjo.utils.Enums;
import com.example.covid19shahajjo.utils.SharedStorge;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;


public class Covid19StoryActivity extends AppCompatActivity {

private DatabaseReference databaseReference;
private RecyclerView storyRecyclerView;
private Covid19StoryActivity covid19StoryActivity;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_covid19_story);
covid19StoryActivity=this;
setUserPreferableTitle();


storyRecyclerView = (RecyclerView) findViewById(R.id.recyclerview_video);
storyRecyclerView.setHasFixedSize(true);
storyRecyclerView.setLayoutManager(new LinearLayoutManager(this));

databaseReference = FirebaseDatabase.getInstance().getReference("video");

YouTubeVideos youTubeVideos=new YouTubeVideos(covid19StoryActivity,null,null);


youTubeVideos.getYoutubeVideoData(databaseReference,storyRecyclerView);



}

@Override
protected void onPause() {
super.onPause();
}

private void setUserPreferableTitle(){
Enums.Language language = SharedStorge.getUserLanguage(this);
if(language == Enums.Language.BD){
String title = getResources().getString(R.string.covid_story_title_bd);
setTitle(title);
}else{
setTitle("Covid-19 Story");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class HomeActivity extends AppCompatActivity implements AdapterView.OnIte
private final int STATISTICS_POSITION = 3;
private final int SETTINGS_POSITION = 4;
private final int ABOUT_POSITION = 5;
private final int VIDEO_STORY_POSITION = 6;


private PermissionChecker permissionChecker;

Expand Down Expand Up @@ -117,6 +119,10 @@ else if(position == TEST_CENTER_POSITION){
Intent intent = new Intent(this, TestCenterActivity.class);
startActivity(intent);
}
else if(position==VIDEO_STORY_POSITION){
Intent intent = new Intent(this, Covid19StoryActivity.class);
startActivity(intent);
}
}

private void goPageIfConnected(Class<?> destinationClass){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.example.covid19shahajjo.activities;

import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import com.example.covid19shahajjo.R;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.PlayerConstants;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.YouTubePlayer;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners.AbstractYouTubePlayerListener;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView;

public class YoutubeFullScreenActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_youtube_full_screen);

YouTubePlayerView youTubePlayerView = findViewById(R.id.youtube_player_view);
getLifecycle().addObserver(youTubePlayerView);

youTubePlayerView.addYouTubePlayerListener(new AbstractYouTubePlayerListener() {
@Override
public void onReady(YouTubePlayer youTubePlayer) {
super.onReady(youTubePlayer);
String url =getIntent().getExtras().getString("url");
Float playerCurrentSecondPlayed=getIntent().getExtras().getFloat("playerCurrentSecondPlayed");
youTubePlayer.loadVideo(url,playerCurrentSecondPlayed);
}

@Override
public void onStateChange(YouTubePlayer youTubePlayer, PlayerConstants.PlayerState state) {
super.onStateChange(youTubePlayer, state);


}
});

//full screen listener
youTubePlayerView.getPlayerUiController().setFullScreenButtonClickListener(new View.OnClickListener() {

@Override
public void onClick(View view) {

//Destroy activity
finish();
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ private int getDrawable(int position){
case 3: return R.drawable.ic_statistics;
case 4: return R.drawable.ic_settings;
case 5: return R.drawable.ic_about;
case 6: return R.drawable.ic_video_story;
default: return -1;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package com.example.covid19shahajjo.adapters;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.covid19shahajjo.R;
import com.example.covid19shahajjo.activities.Covid19StoryActivity;
import com.example.covid19shahajjo.activities.YoutubeFullScreenActivity;
import com.example.covid19shahajjo.models.YouTubeVideos;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.PlayerConstants;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.YouTubePlayer;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners.AbstractYouTubePlayerListener;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView;

import java.util.ArrayList;
import java.util.List;

public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoViewHolder> {

private Covid19StoryActivity covid19StoryActivity;
private ArrayList<YouTubePlayer> youTubePlayerArrayList = new ArrayList<>();
private RecyclerView storyRecyclerView;
private boolean isPlaying=false;
private float playerCurrentSecondPlayed=0;
List<YouTubeVideos>youTubeVideosList;


public VideoAdapter(List<YouTubeVideos> youTubeVideosList, Covid19StoryActivity covid19StoryActivity, RecyclerView storyRecyclerView) {
this.youTubeVideosList = youTubeVideosList;
this.covid19StoryActivity=covid19StoryActivity;
this.storyRecyclerView=storyRecyclerView;
}

@NonNull
@Override
public VideoViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.video_view,parent,false);

return new VideoViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull VideoViewHolder holder, int position) {

holder.tileTextView.setText(youTubeVideosList.get(position).getTitle());


//full screen youtube player listener
holder.youTubePlayerView.getPlayerUiController().setFullScreenButtonClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

Intent myIntent = new Intent(covid19StoryActivity, YoutubeFullScreenActivity.class);
myIntent.putExtra("url", youTubeVideosList.get(position).getUrl()); //Optional parameters
myIntent.putExtra("playerCurrentSecondPlayed", playerCurrentSecondPlayed); //Optional parameters
covid19StoryActivity.startActivity(myIntent);
}
});


holder.youTubePlayerView.addYouTubePlayerListener(new AbstractYouTubePlayerListener(){


@Override
public void onReady(YouTubePlayer youTubePlayer) {

covid19StoryActivity.getLifecycle().addObserver(holder.youTubePlayerView);
youTubePlayer.cueVideo(youTubeVideosList.get(position).getUrl(),0);
youTubePlayerArrayList.add(youTubePlayer);


//scrolling listener
storyRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);

}

@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if(isPlaying==true) pauseAllPlayer();
isPlaying=false;


}
});


}



@Override
public void onStateChange(YouTubePlayer youTubePlayer, PlayerConstants.PlayerState state) {


if(state.toString().equals("PLAYING") || state.toString().equals("BUFFERING") || state.toString().equals("UNKNOWN")){
if(isPlaying==true){
pauseAllPlayer();
youTubePlayer.play();
}
isPlaying=true;

}else isPlaying=false;//ENDED,PAUSED,VIDEO_CUED,UNSTARTED
}

@Override
public void onCurrentSecond(YouTubePlayer youTubePlayer, float second) {
super.onCurrentSecond(youTubePlayer, second);
playerCurrentSecondPlayed=second;
}
});


}



@Override
public int getItemCount() {
return youTubeVideosList.size();
}

private void pauseAllPlayer(){
for(int i=0;i<youTubePlayerArrayList.size();i++){
youTubePlayerArrayList.get(i).pause();
}
}



public class VideoViewHolder extends RecyclerView.ViewHolder {
TextView tileTextView;


//youtube player
YouTubePlayerView youTubePlayerView;

public VideoViewHolder(@NonNull View itemView) {
super(itemView);
tileTextView =(TextView) itemView.findViewById(R.id.YoutubeVideoTitleId);


youTubePlayerView =(YouTubePlayerView)itemView.findViewById(R.id.youtube_player_view);

}


}
}
Loading

0 comments on commit 2bade82

Please sign in to comment.