Skip to content

Commit 6cb7d38

Browse files
authored
Merge pull request #5 from TeamStreamix/dev
ReleaseV1.0
2 parents 5818a41 + 28e4d67 commit 6cb7d38

33 files changed

+2393
-133
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
.externalNativeBuild
1414
.cxx
1515
local.properties
16+
.env

app/build.gradle

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ android {
1717
}
1818

1919
buildTypes {
20+
debug {
21+
buildConfigField("String", "FILE_SYSTEM_URL", "\"http://192.168.1.4:8080/\"")
22+
buildConfigField("String", "SERVER_URL", "\"http://192.168.1.4:4000/\"")
23+
}
2024
release {
25+
buildConfigField("String", "FILE_SYSTEM_URL", "\"http://192.168.1.4:8080\"")
26+
buildConfigField("String", "SERVER_URL", "\"http://192.168.1.4:4000/\"")
2127
minifyEnabled false
2228
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
2329
}
@@ -31,13 +37,18 @@ android {
3137
}
3238
}
3339

40+
def mediaVersion = "2.18.1"
41+
3442
dependencies {
3543

3644
// dependency for exoplayer
37-
implementation 'com.google.android.exoplayer:exoplayer-core:2.18.1'
38-
implementation 'com.google.android.exoplayer:exoplayer-dash:2.18.1'
39-
implementation 'com.google.android.exoplayer:exoplayer-hls:2.18.1'
40-
implementation 'com.google.android.exoplayer:exoplayer-ui:2.18.1'
45+
implementation "com.google.android.exoplayer:exoplayer-core:$mediaVersion"
46+
implementation "com.google.android.exoplayer:exoplayer-dash:$mediaVersion"
47+
implementation "com.google.android.exoplayer:exoplayer-hls:$mediaVersion"
48+
implementation "com.google.android.exoplayer:exoplayer-ui:$mediaVersion"
49+
50+
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
51+
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
4152

4253

4354
implementation 'androidx.appcompat:appcompat:1.5.1'
@@ -49,4 +60,10 @@ dependencies {
4960
testImplementation 'junit:junit:4.13.2'
5061
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
5162
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
63+
64+
implementation 'com.squareup.picasso:picasso:2.8'
65+
implementation 'com.squareup.okhttp3:okhttp:3.3.1'
66+
67+
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
68+
5269
}

app/src/main/AndroidManifest.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
1010

1111
<application
12+
android:requestLegacyExternalStorage="true"
1213
android:allowBackup="true"
1314
android:dataExtractionRules="@xml/data_extraction_rules"
1415
android:fullBackupContent="@xml/backup_rules"
@@ -17,7 +18,8 @@
1718
android:roundIcon="@mipmap/streamix_logo_round"
1819
android:supportsRtl="true"
1920
android:theme="@style/Theme.StreamiX.DarkTheme"
20-
tools:targetApi="31">
21+
tools:targetApi="31"
22+
android:usesCleartextTraffic="true">
2123

2224
<activity
2325
android:name=".PlayerActivity"
@@ -28,6 +30,15 @@
2830
android:value="" />
2931
</activity>
3032

33+
<activity
34+
android:name=".videoUploadForm"
35+
android:exported="false"
36+
android:theme="@style/Theme.StreamiX.DarkTheme">
37+
<meta-data
38+
android:name="android.app.lib_name"
39+
android:value="" />
40+
</activity>
41+
3142
<activity
3243
android:name=".MainActivity"
3344
android:exported="true"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.supun.streamix;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
6+
import okhttp3.MultipartBody;
7+
import okhttp3.RequestBody;
8+
import okhttp3.ResponseBody;
9+
import retrofit2.Call;
10+
import retrofit2.http.GET;
11+
import retrofit2.http.Multipart;
12+
import retrofit2.http.POST;
13+
import retrofit2.http.Part;
14+
import retrofit2.http.PartMap;
15+
import retrofit2.http.Path;
16+
import retrofit2.http.Streaming;
17+
18+
public interface API {
19+
20+
// @GET("fileUpload/")
21+
// Call<List<Image>> getImages(); // GET request to get all images
22+
//
23+
// @GET("fileUpload/files/{filename}") // GET request to get an image by its name
24+
// @Streaming
25+
// Call<ResponseBody> getImageByName(@Path("filename") String name);
26+
27+
@GET("getVideos")
28+
Call<List<Video>> getVideos();
29+
30+
@Multipart // POST request to upload an image from storage
31+
@POST("upload")
32+
Call<ResponseBody> uploadVideo(@Part MultipartBody.Part video, @PartMap Map<String,RequestBody> requestBody);
33+
}

app/src/main/java/com/supun/streamix/HomeFragment.java

Lines changed: 130 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22

33
import android.animation.AnimatorSet;
44
import android.animation.ValueAnimator;
5+
import android.content.Context;
56
import android.content.Intent;
7+
import android.graphics.Bitmap;
8+
import android.graphics.BitmapFactory;
9+
import android.graphics.Canvas;
10+
import android.graphics.drawable.Drawable;
11+
import android.os.AsyncTask;
12+
import android.os.Build;
613
import android.os.Bundle;
14+
import android.os.StrictMode;
715
import android.util.Log;
816
import android.view.LayoutInflater;
917
import android.view.View;
@@ -12,33 +20,70 @@
1220

1321
import androidx.annotation.NonNull;
1422
import androidx.annotation.Nullable;
23+
import androidx.core.content.ContextCompat;
24+
import androidx.core.graphics.drawable.DrawableCompat;
1525
import androidx.fragment.app.Fragment;
1626
import androidx.recyclerview.widget.LinearLayoutManager;
1727
import androidx.recyclerview.widget.RecyclerView;
28+
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
1829

1930
import com.supun.streamix.ui.videoCard.IRecyclerView;
2031
import com.supun.streamix.ui.videoCard.VC_RecycleViewAdapter;
2132
import com.supun.streamix.ui.videoCard.VideoCardModel;
2233

34+
import java.io.InputStream;
35+
import java.net.URL;
2336
import java.util.ArrayList;
37+
import java.util.List;
2438

25-
public class HomeFragment extends Fragment implements IRecyclerView {
39+
import retrofit2.Call;
40+
import retrofit2.Callback;
41+
import retrofit2.Response;
2642

27-
private static final ArrayList<VideoCardModel> videoCardModels = new ArrayList<>();
43+
public class HomeFragment extends Fragment implements IRecyclerView, SwipeRefreshLayout.OnRefreshListener {
44+
45+
private final ArrayList<VideoCardModel> videoCardModels = new ArrayList<>();
2846
private MainActivity mainActivity;
47+
private VC_RecycleViewAdapter adapter;
48+
49+
private SwipeRefreshLayout swipeRefreshLayout;
50+
51+
@Override
52+
public void onCreate(@Nullable Bundle savedInstanceState) {
53+
super.onCreate(savedInstanceState);
54+
}
2955

3056
@Nullable
3157
@Override
3258
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
3359

3460
mainActivity = (MainActivity) getActivity();
3561

62+
// Avoid network op on main thread for loading thumbnails - Reduce UX
63+
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
64+
StrictMode.setThreadPolicy(policy);
65+
3666

3767
View view = inflater.inflate(R.layout.fragment_home, container, false);
3868

69+
swipeRefreshLayout = view.findViewById(R.id.swipe_container);
70+
swipeRefreshLayout.setOnRefreshListener(this);
71+
swipeRefreshLayout.setColorSchemeResources(
72+
R.color.red_900,
73+
R.color.yellow_100,
74+
R.color.black,
75+
R.color.purple_700
76+
);
77+
78+
swipeRefreshLayout.post(() -> {
79+
swipeRefreshLayout.setRefreshing(true);
80+
setupVideoCardModels();
81+
82+
Log.i("zz", String.valueOf(videoCardModels.size()));
83+
});
84+
3985
RecyclerView recyclerView = view.findViewById(R.id.recycler_view_home);
40-
setupVideoCardModels();
41-
VC_RecycleViewAdapter adapter = new VC_RecycleViewAdapter(getContext(), videoCardModels, this);
86+
adapter = new VC_RecycleViewAdapter(getContext(), videoCardModels, this);
4287

4388
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
4489
recyclerView.setAdapter(adapter);
@@ -87,52 +132,85 @@ else if(dy < -10){
87132
private void setupVideoCardModels(){
88133

89134
// This is to prevent duplicating items when orientation change
135+
136+
swipeRefreshLayout.setRefreshing(true);
137+
90138
videoCardModels.clear();
139+
adapter.clear();
140+
141+
ArrayList<String> ids = new ArrayList<>();
142+
143+
String Tag = "ASYNC";
144+
Log.i(Tag, "Starting");
145+
Call<List<Video>> call = RetrofitClient.getInstance().getAPI().getVideos();
146+
Log.i(Tag, "call ");
147+
call.enqueue(new Callback<List<Video>>() {
148+
@Override
149+
public void onResponse(Call<List<Video>> call, Response<List<Video>> response) {
150+
Log.i(Tag, "Got data");
151+
List<Video> videoList = response.body();
152+
Log.i("size", String.valueOf(videoList.size()));
153+
Log.i(Tag, videoList.get(0).getTitle());
154+
Log.i(Tag, videoList.get(0).getDescription());
155+
for (int i = 0; i < videoList.size(); i++) {
156+
Log.i(Tag, "xxxx");
157+
if (!ids.contains(videoList.get(i).getID())){
158+
ids.add(videoList.get(i).getID());
159+
160+
Bitmap thumbnail;
161+
162+
try{
163+
Log.i("THUMBNAIL_LINK", BuildConfig.FILE_SYSTEM_URL+ "thumbnails/" + videoList.get(i).getID() + ".jpg");
164+
URL in = new URL(BuildConfig.FILE_SYSTEM_URL+ "thumbnails/" + videoList.get(i).getID() + ".jpg");
165+
166+
167+
thumbnail = BitmapFactory.decodeStream(in.openConnection().getInputStream());
168+
} catch (Exception e){
169+
Log.i("THUMBNAIL", e.toString());
170+
thumbnail = getBitmapFromVectorDrawable(getContext(), R.drawable.no_thumbnail_available);
171+
}
172+
91173

92-
// These are the dummy data used to display
93-
String[] titles = {"Video 1", "Video 2", "Video 3", "Video 4", "Video 5", "Video 1", "Video 2", "Video 3", "Video 4", "Video 5"};
94-
String[] descriptions = {
95-
"This is a description for video 1",
96-
"This is a description for video 2",
97-
"This is a description for video 3",
98-
"This is a description for video 4",
99-
"This is a description for video 5",
100-
"This is a description for video 1",
101-
"This is a description for video 2",
102-
"This is a description for video 3",
103-
"This is a description for video 4",
104-
"This is a description for video 5"
105-
};
106-
107-
int[] vectorImages = {
108-
R.drawable.thumbnail_1,
109-
R.drawable.thumbnail_2,
110-
R.drawable.thumbnail_3,
111-
R.drawable.no_thumbnail_available,
112-
R.drawable.no_thumbnail_available,
113-
R.drawable.no_thumbnail_available,
114-
R.drawable.no_thumbnail_available,
115-
R.drawable.no_thumbnail_available,
116-
R.drawable.no_thumbnail_available,
117-
R.drawable.no_thumbnail_available
118-
};
119-
120-
String[] associatedUrls= {
121-
"https://samplelib.com/lib/preview/mp4/sample-5s.mp4",
122-
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/TearsOfSteel.mp4",
123-
"https://media.geeksforgeeks.org/wp-content/uploads/20201217163353/Screenrecorder-2020-12-17-16-32-03-350.mp4",
124-
"https://samplelib.com/lib/preview/mp4/sample-30s.mp4",
125-
"https://samplelib.com/lib/preview/mp4/sample-30s.mp4",
126-
"https://samplelib.com/lib/preview/mp4/sample-5s.mp4",
127-
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/TearsOfSteel.mp4",
128-
"https://media.geeksforgeeks.org/wp-content/uploads/20201217163353/Screenrecorder-2020-12-17-16-32-03-350.mp4",
129-
"https://samplelib.com/lib/preview/mp4/sample-30s.mp4",
130-
"https://samplelib.com/lib/preview/mp4/sample-30s.mp4"
131-
};
132-
133-
for(int i = 0; i < titles.length; i++){
134-
videoCardModels.add(new VideoCardModel(vectorImages[i], titles[i], descriptions[i], associatedUrls[i]));
174+
175+
videoCardModels.add(new VideoCardModel(
176+
thumbnail,
177+
videoList.get(i).getTitle(),
178+
videoList.get(i).getDescription(),
179+
BuildConfig.FILE_SYSTEM_URL+videoList.get(i).getID()+"/"+videoList.get(i).getID()+"_out.mpd"));
180+
181+
adapter.notifyItemInserted(videoCardModels.size() - 1);
182+
}
183+
184+
}
185+
Log.i("qqq", String.valueOf(videoCardModels.size()));
186+
187+
swipeRefreshLayout.setRefreshing(false);
188+
}
189+
190+
@Override
191+
public void onFailure(Call<List<Video>> call, Throwable t) {
192+
193+
Log.e(Tag, "Mission Faileddddd");
194+
// Toast.makeText(getApplicationContext(), "An error has occured", Toast.LENGTH_LONG).show();
195+
}
196+
197+
});
198+
199+
}
200+
201+
public static Bitmap getBitmapFromVectorDrawable(Context context, int drawableId) {
202+
Drawable drawable = ContextCompat.getDrawable(context, drawableId);
203+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
204+
drawable = (DrawableCompat.wrap(drawable)).mutate();
135205
}
206+
207+
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
208+
drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
209+
Canvas canvas = new Canvas(bitmap);
210+
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
211+
drawable.draw(canvas);
212+
213+
return bitmap;
136214
}
137215

138216
@Override
@@ -173,4 +251,9 @@ public static void slideView(View view,
173251
animationSet.start();
174252
}
175253

254+
@Override
255+
public void onRefresh() {
256+
setupVideoCardModels();
257+
Log.i("SWIPE_REFRESH", "Swipe refresh executed");
258+
}
176259
}

0 commit comments

Comments
 (0)