Skip to content

Commit 1783ebc

Browse files
authored
Merge pull request #42 from Capstone-Projects-2023-Spring/MPC-145-Camera-Share-from-an-account-to-another
MPC-145-Camera-Share-from-an-account-to-another
2 parents 65cff8a + 5bb500f commit 1783ebc

File tree

13 files changed

+472
-101
lines changed

13 files changed

+472
-101
lines changed

Android/Layout_Version/app/src/main/java/com/example/layout_version/MainTab/Streaming/StreamingFragment.java

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
import android.content.Context;
44
import android.net.Uri;
55
import android.os.Bundle;
6+
import android.util.Log;
67
import android.view.LayoutInflater;
78
import android.view.View;
89
import android.view.ViewGroup;
10+
import android.widget.Button;
11+
import android.widget.EditText;
912
import android.widget.FrameLayout;
1013
import android.widget.ImageButton;
1114
import android.widget.TextView;
15+
import android.widget.Toast;
1216

1317
import androidx.annotation.NonNull;
1418
import androidx.annotation.Nullable;
19+
import androidx.appcompat.app.AlertDialog;
1520
import androidx.appcompat.content.res.AppCompatResources;
1621
import androidx.lifecycle.ViewModelProvider;
1722

@@ -22,8 +27,14 @@
2227
import com.example.layout_version.MainTab.Streaming.Recorder.Recorder;
2328
import com.example.layout_version.MainTab.Streaming.Recorder.RecordingState;
2429
import com.example.layout_version.MainTab.Streaming.Recorder.RecordingStateChangeListener;
30+
import com.example.layout_version.Network.NetworkRequestManager;
2531
import com.example.layout_version.R;
2632

33+
import org.json.JSONException;
34+
import org.json.JSONObject;
35+
36+
import java.util.Map;
37+
2738
public class StreamingFragment extends StateFragment<RecordingState> {
2839
private Context context;
2940
private StreamingViewModel streamingViewModel;
@@ -35,8 +46,12 @@ public class StreamingFragment extends StateFragment<RecordingState> {
3546
private ImageButton recordingButton;
3647
private ImageButton streamRefreshButton;
3748

49+
private ImageButton optionButton;
50+
private ImageButton shareButton;
3851
private Recorder recorder;
3952

53+
private boolean optionFlag;
54+
4055
@Override
4156
public View onCreateView(LayoutInflater inflater, ViewGroup container,
4257
Bundle savedInstanceState) {
@@ -59,8 +74,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
5974
deviceStatusView = layout.findViewById(R.id.deviceStatusView);
6075
recordingButton = layout.findViewById(R.id.recordingButton);
6176
streamRefreshButton = layout.findViewById(R.id.streamRefreshButton);
77+
optionButton = layout.findViewById(R.id.optionButton);
78+
shareButton = layout.findViewById(R.id.shareButton);
6279
recorder = new Recorder(context, streamingViewModel);
6380

81+
hideOptions();
82+
6483
return layout;
6584
}
6685

@@ -87,6 +106,16 @@ else if(status == RecordingState.FAILED)
87106
update(streamingViewModel.getSelectedItem().getValue());
88107
});
89108

109+
optionButton.setOnClickListener(view1 -> {
110+
if(optionFlag)
111+
hideOptions();
112+
else
113+
showOptions();
114+
});
115+
116+
shareButton.setOnClickListener(view1 -> {
117+
showShareDialog();
118+
});
90119
}
91120

92121
public void update(@Nullable ChannelItem channel)
@@ -114,4 +143,79 @@ public void onDestroy() {
114143
streamingPlayer.removeListener(playerListener);
115144
streamingPlayer.release();
116145
}
146+
147+
public void hideOptions()
148+
{
149+
optionFlag = false;
150+
optionButton.setImageDrawable(AppCompatResources.getDrawable(context, R.drawable.baseline_vert_options_24));
151+
recordingButton.setVisibility(View.INVISIBLE);
152+
shareButton.setVisibility(View.INVISIBLE);
153+
}
154+
155+
public void showOptions()
156+
{
157+
optionFlag = true;
158+
optionButton.setImageDrawable(AppCompatResources.getDrawable(context, R.drawable.baseline_close_24));
159+
recordingButton.setVisibility(View.VISIBLE);
160+
shareButton.setVisibility(View.VISIBLE);
161+
}
162+
163+
public void showShareDialog()
164+
{
165+
View view = getActivity().getLayoutInflater().inflate(R.layout.device_share, null);
166+
TextView codeText = view.findViewById(R.id.codeTextView);
167+
EditText codeEditText = view.findViewById(R.id.codeEdit);
168+
Button connectButton = view.findViewById(R.id.connectButton);
169+
Button shareButton = view.findViewById(R.id.shareButton);
170+
171+
codeText.setVisibility(View.INVISIBLE);
172+
codeEditText.setText("");
173+
174+
connectButton.setOnClickListener(view1 -> {
175+
Log.e("Connect", "here");
176+
177+
Log.e("Share", "here");
178+
NetworkRequestManager nrm = new NetworkRequestManager(context);
179+
JSONObject jsonObject = new JSONObject(Map.of(
180+
"token", Account.getInstance().getTokenData().getValue(),
181+
"code", codeEditText.getText().toString()
182+
));
183+
nrm.Post(R.string.device_code_endpoint, jsonObject,
184+
json -> {
185+
Toast.makeText(context, "Successfully connected device to account", Toast.LENGTH_SHORT).show();
186+
},
187+
json->{
188+
Toast.makeText(context, "Error", Toast.LENGTH_SHORT).show();
189+
});
190+
});
191+
192+
shareButton.setOnClickListener(view1 -> {
193+
NetworkRequestManager nrm = new NetworkRequestManager(context);
194+
JSONObject jsonObject = new JSONObject(Map.of(
195+
"token", Account.getInstance().getTokenData().getValue(),
196+
"device_id", streamingViewModel.getSelectedItem().getValue().getDeviceId()
197+
));
198+
nrm.Post(R.string.device_share_endpoint, jsonObject,
199+
json -> {
200+
String code = null;
201+
try {
202+
code = json.getString("code");
203+
codeText.setText(code);
204+
} catch (JSONException e) {
205+
codeText.setText("Error");
206+
}
207+
codeText.setVisibility(View.VISIBLE);
208+
},
209+
json->{
210+
codeText.setText("Error");
211+
codeText.setVisibility(View.VISIBLE);
212+
});
213+
});
214+
215+
new AlertDialog.Builder(getActivity())
216+
.setView(view)
217+
.show();
218+
}
219+
220+
117221
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:autoMirrored="true" android:height="24dp"
2+
android:tint="#222222" android:viewportHeight="24"
3+
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M11,7L9.6,8.4l2.6,2.6H2v2h10.2l-2.6,2.6L11,17l5,-5L11,7zM20,19h-8v2h8c1.1,0 2,-0.9 2,-2V5c0,-1.1 -0.9,-2 -2,-2h-8v2h8V19z"/>
5+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:autoMirrored="true" android:height="24dp"
2+
android:tint="#222222" android:viewportHeight="24"
3+
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M17,7l-1.41,1.41L18.17,11H8v2h10.17l-2.58,2.58L17,17l5,-5zM4,5h8V3H4c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h8v-2H4V5z"/>
5+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="24dp" android:tint="#555555"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z"/>
5+
</vector>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
3+
<stroke
4+
android:width="0dp" />
5+
6+
<solid android:color="#4dace3" />
7+
8+
<padding
9+
android:left="1dp"
10+
android:right="1dp"
11+
android:bottom="1dp"
12+
android:top="1dp" />
13+
14+
<corners android:radius="10dp" />
15+
</shape>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
3+
<stroke
4+
android:width="0dp" />
5+
6+
<solid android:color="#dede49" />
7+
8+
<padding
9+
android:left="1dp"
10+
android:right="1dp"
11+
android:bottom="1dp"
12+
android:top="1dp" />
13+
14+
<corners android:radius="10dp" />
15+
</shape>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
3+
<stroke
4+
android:width="0dp" />
5+
6+
<solid android:color="#FFFFFF" />
7+
8+
<padding
9+
android:left="1dp"
10+
android:right="1dp"
11+
android:bottom="1dp"
12+
android:top="1dp" />
13+
14+
<corners android:radius="20dp" />
15+
</shape>

0 commit comments

Comments
 (0)