Skip to content

Commit 28e4d67

Browse files
authored
Merge pull request #4 from TeamStreamix/bugFix-Supun
App Refine and Bugs Fixed
2 parents 4b83d80 + b372f24 commit 28e4d67

File tree

13 files changed

+285
-135
lines changed

13 files changed

+285
-135
lines changed

.idea/deploymentTargetDropDown.xml

Lines changed: 0 additions & 17 deletions
This file was deleted.

.idea/gradle.xml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ android {
1818

1919
buildTypes {
2020
debug {
21-
buildConfigField("String", "FILE_SYSTEM_URL", "\"http://192.168.1.10:8080/\"")
22-
buildConfigField("String", "SERVER_URL", "\"http://192.168.1.10:4000/\"")
21+
buildConfigField("String", "FILE_SYSTEM_URL", "\"http://192.168.1.4:8080/\"")
22+
buildConfigField("String", "SERVER_URL", "\"http://192.168.1.4:4000/\"")
2323
}
2424
release {
25-
buildConfigField("String", "FILE_SYSTEM_URL", "\"http://192.168.1.10:8080/\"")
26-
buildConfigField("String", "SERVER_URL", "\"http://192.168.1.10:4000/\"")
25+
buildConfigField("String", "FILE_SYSTEM_URL", "\"http://192.168.1.4:8080\"")
26+
buildConfigField("String", "SERVER_URL", "\"http://192.168.1.4:4000/\"")
2727
minifyEnabled false
2828
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
2929
}
@@ -62,4 +62,8 @@ dependencies {
6262
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
6363

6464
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+
6569
}

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

Lines changed: 94 additions & 52 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,39 +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;
2437
import java.util.List;
2538

2639
import retrofit2.Call;
2740
import retrofit2.Callback;
2841
import retrofit2.Response;
2942

30-
public class HomeFragment extends Fragment implements IRecyclerView {
43+
public class HomeFragment extends Fragment implements IRecyclerView, SwipeRefreshLayout.OnRefreshListener {
3144

32-
private static final ArrayList<VideoCardModel> videoCardModels = new ArrayList<>();
45+
private final ArrayList<VideoCardModel> videoCardModels = new ArrayList<>();
3346
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+
}
3455

3556
@Nullable
3657
@Override
3758
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
3859

3960
mainActivity = (MainActivity) getActivity();
4061

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+
4166

4267
View view = inflater.inflate(R.layout.fragment_home, container, false);
4368

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+
4485
RecyclerView recyclerView = view.findViewById(R.id.recycler_view_home);
45-
setupVideoCardModels();
46-
Log.i("zz", String.valueOf(videoCardModels.size()));
47-
VC_RecycleViewAdapter adapter = new VC_RecycleViewAdapter(getContext(), videoCardModels, this);
86+
adapter = new VC_RecycleViewAdapter(getContext(), videoCardModels, this);
4887

4988
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
5089
recyclerView.setAdapter(adapter);
@@ -93,10 +132,15 @@ else if(dy < -10){
93132
private void setupVideoCardModels(){
94133

95134
// This is to prevent duplicating items when orientation change
96-
// videoCardModels.clear();
135+
136+
swipeRefreshLayout.setRefreshing(true);
137+
138+
videoCardModels.clear();
139+
adapter.clear();
140+
97141
ArrayList<String> ids = new ArrayList<>();
98142

99-
String Tag = "vhagar";
143+
String Tag = "ASYNC";
100144
Log.i(Tag, "Starting");
101145
Call<List<Video>> call = RetrofitClient.getInstance().getAPI().getVideos();
102146
Log.i(Tag, "call ");
@@ -112,13 +156,35 @@ public void onResponse(Call<List<Video>> call, Response<List<Video>> response) {
112156
Log.i(Tag, "xxxx");
113157
if (!ids.contains(videoList.get(i).getID())){
114158
ids.add(videoList.get(i).getID());
115-
videoCardModels.add(new VideoCardModel(R.drawable.thumbnail_1, videoList.get(i).getTitle(),
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+
173+
174+
175+
videoCardModels.add(new VideoCardModel(
176+
thumbnail,
177+
videoList.get(i).getTitle(),
116178
videoList.get(i).getDescription(),
117179
BuildConfig.FILE_SYSTEM_URL+videoList.get(i).getID()+"/"+videoList.get(i).getID()+"_out.mpd"));
180+
181+
adapter.notifyItemInserted(videoCardModels.size() - 1);
118182
}
119183

120184
}
121185
Log.i("qqq", String.valueOf(videoCardModels.size()));
186+
187+
swipeRefreshLayout.setRefreshing(false);
122188
}
123189

124190
@Override
@@ -129,53 +195,24 @@ public void onFailure(Call<List<Video>> call, Throwable t) {
129195
}
130196

131197
});
132-
// These are the dummy data used to display
133-
// String[] titles = {"Video 1", "Video 2", "Video 3", "Video 4", "Video 5", "Video 1", "Video 2", "Video 3", "Video 4", "Video 5"};
134-
// String[] descriptions = {
135-
// "This is a description for video 1",
136-
// "This is a description for video 2",
137-
// "This is a description for video 3",
138-
// "This is a description for video 4",
139-
// "This is a description for video 5",
140-
// "This is a description for video 1",
141-
// "This is a description for video 2",
142-
// "This is a description for video 3",
143-
// "This is a description for video 4",
144-
// "This is a description for video 5"
145-
// };
146-
147-
int[] vectorImages = {
148-
R.drawable.thumbnail_1,
149-
R.drawable.thumbnail_2,
150-
R.drawable.thumbnail_3,
151-
R.drawable.no_thumbnail_available,
152-
R.drawable.no_thumbnail_available,
153-
R.drawable.no_thumbnail_available,
154-
R.drawable.no_thumbnail_available,
155-
R.drawable.no_thumbnail_available,
156-
R.drawable.no_thumbnail_available,
157-
R.drawable.no_thumbnail_available
158-
};
159-
160-
// String[] associatedUrls= {
161-
// "http://192.168.1.15:8080/a/a_out.mpd",
162-
// "http://192.168.1.15:8080/c/c_out.mpd",
163-
// "http://192.168.1.15:8080/b/videofull1_out.mpd",
164-
// "https://content.jwplatform.com/manifests/yp34SRmf.m3u8",
165-
// "https://dash.akamaized.net/dash264/TestCasesIOP33/adapatationSetSwitching/5/manifest.mpd",
166-
// "https://samplelib.com/lib/preview/mp4/sample-5s.mp4",
167-
// "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/TearsOfSteel.mp4",
168-
// "https://media.geeksforgeeks.org/wp-content/uploads/20201217163353/Screenrecorder-2020-12-17-16-32-03-350.mp4",
169-
// "https://samplelib.com/lib/preview/mp4/sample-30s.mp4",
170-
// "https://samplelib.com/lib/preview/mp4/sample-30s.mp4"
171-
// };
172-
173-
// for(int i = 0; i < titles.size(); i++){
174-
// videoCardModels.add(new VideoCardModel(vectorImages[0], titles.get(i), descriptions.get(i), associatedUrls.get(i)));
175-
// }
176198

177199
}
178200

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();
205+
}
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;
214+
}
215+
179216
@Override
180217
public void onCardClick(int position) {
181218
Intent intent = new Intent(getActivity(), PlayerActivity.class);
@@ -214,4 +251,9 @@ public static void slideView(View view,
214251
animationSet.start();
215252
}
216253

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

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.supun.streamix;
22

33
import android.annotation.SuppressLint;
4+
import android.content.Context;
45
import android.content.Intent;
56
import android.content.SharedPreferences;
67
import android.database.Cursor;
78
import android.net.Uri;
9+
import android.os.Build;
810
import android.os.Bundle;
911

1012
import com.google.android.material.card.MaterialCardView;
@@ -31,6 +33,14 @@
3133
import com.supun.streamix.ui.main.SectionsPagerAdapter;
3234
import com.supun.streamix.databinding.ActivityMainBinding;
3335

36+
import java.io.File;
37+
import java.io.FileNotFoundException;
38+
import java.io.FileOutputStream;
39+
import java.io.IOException;
40+
import java.io.InputStream;
41+
import java.io.OutputStream;
42+
import java.time.LocalDateTime;
43+
3444
public class MainActivity extends AppCompatActivity {
3545

3646
private ActivityMainBinding binding;
@@ -45,6 +55,7 @@ public class MainActivity extends AppCompatActivity {
4555

4656

4757

58+
4859
@Override
4960
public boolean onCreateOptionsMenu(Menu menu) {
5061
this.menu = menu;
@@ -64,6 +75,8 @@ protected void onCreate(Bundle savedInstanceState) {
6475

6576

6677

78+
79+
6780
binding = ActivityMainBinding.inflate(getLayoutInflater());
6881

6982

@@ -84,8 +97,6 @@ protected void onCreate(Bundle savedInstanceState) {
8497
try{
8598
Intent intent = new Intent();
8699
intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE);
87-
// intent.putExtra() : Pass extras to the new Activity
88-
89100

90101
startActivityForResult(intent, recordCode);
91102

@@ -177,11 +188,12 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
177188

178189
Intent intent = new Intent(this, videoUploadForm.class);
179190

180-
181191
intent.putExtra("VIDEO_URL", videoUri.toString());
182192

183193
startActivity(intent);
184194

195+
finish();
196+
185197
Log.i("RESULT_OK", "onActivityResult: Video captured");
186198
} else if(resultCode == RESULT_CANCELED){
187199
Log.i("CAMERA_CLOSE", "onActivityResult: Camera Closed");
@@ -190,4 +202,5 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
190202
}
191203
}
192204
}
205+
193206
}

0 commit comments

Comments
 (0)