-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from swesust/development/foysal
Development/foysal
- Loading branch information
Showing
24 changed files
with
638 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...ahajjo/app/src/main/java/com/example/covid19shahajjo/activities/Covid19StoryActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...o/app/src/main/java/com/example/covid19shahajjo/activities/YoutubeFullScreenActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
Covid19Shahajjo/app/src/main/java/com/example/covid19shahajjo/adapters/VideoAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.