Skip to content

Commit bd719db

Browse files
committed
Loading animation and sending stream info via email
1 parent 9eaeae6 commit bd719db

File tree

8 files changed

+107
-14
lines changed

8 files changed

+107
-14
lines changed

Android/Layout_Version/app/src/main/java/com/example/layout_version/CameraShare/CameraConnectDialog.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111

1212
import androidx.annotation.NonNull;
1313
import androidx.fragment.app.DialogFragment;
14+
import androidx.lifecycle.ViewModelProvider;
1415

16+
import com.example.layout_version.Account.Account;
17+
import com.example.layout_version.MainTab.Streaming.StreamingListFragmentInterface;
18+
import com.example.layout_version.MainTab.Streaming.StreamingViewModel;
1519
import com.example.layout_version.R;
1620

1721
public class CameraConnectDialog extends DialogFragment implements CameraConnectFragment.CameraShareInterface {
@@ -49,6 +53,8 @@ public void onActivityCreated(Bundle savedInstanceState) {
4953

5054
@Override
5155
public void action() {
56+
StreamingViewModel streamingViewModel = new ViewModelProvider(requireActivity()).get(StreamingViewModel.class);
57+
StreamingListFragmentInterface.loadData(getContext(), streamingViewModel, Account.getInstance().getTokenData().getValue(), 4);
5258
dismiss();
5359
}
5460
}

Android/Layout_Version/app/src/main/java/com/example/layout_version/CameraShare/CameraConnectFragment.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
package com.example.layout_version.CameraShare;
22

3-
import android.app.Activity;
43
import android.content.Context;
54
import android.os.Bundle;
6-
7-
import androidx.fragment.app.Fragment;
8-
import androidx.lifecycle.ViewModelProvider;
9-
105
import android.util.Log;
116
import android.view.LayoutInflater;
127
import android.view.View;
@@ -15,11 +10,9 @@
1510
import android.widget.EditText;
1611
import android.widget.Toast;
1712

13+
import androidx.fragment.app.Fragment;
14+
1815
import com.example.layout_version.Account.Account;
19-
import com.example.layout_version.MainTab.Library.LibraryFragmentInterface;
20-
import com.example.layout_version.MainTab.Library.VideoViewModel;
21-
import com.example.layout_version.MainTab.Streaming.StreamingListFragmentInterface;
22-
import com.example.layout_version.MainTab.Streaming.StreamingViewModel;
2316
import com.example.layout_version.Network.NetworkRequestManager;
2417
import com.example.layout_version.R;
2518

@@ -63,8 +56,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
6356
if(getParentFragment() instanceof CameraShareInterface)
6457
{
6558
((CameraShareInterface)getParentFragment()).action();
66-
StreamingViewModel streamingViewModel = new ViewModelProvider(requireActivity()).get(StreamingViewModel.class);
67-
StreamingListFragmentInterface.loadData(getContext(), streamingViewModel, Account.getInstance().getTokenData().getValue(), 4);
6859
}
6960
},
7061
json->{

Android/Layout_Version/app/src/main/java/com/example/layout_version/ChannelRegisterActivity.java

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,24 @@ protected void onCreate(Bundle savedInstanceState) {
5858
View view = getLayoutInflater().inflate(R.layout.channel_information, null);
5959
TextView ingestEndpoint = view.findViewById(R.id.ingestEndpointTextView);
6060
TextView streamKey = view.findViewById(R.id.streamKeyTextView);
61+
Button emailButton = view.findViewById(R.id.emailButton);
62+
ProgressBar progressBar = view.findViewById(R.id.progressBar);
63+
ImageView networkResultView = view.findViewById(R.id.networkResultView);
6164
try{
6265
JSONObject hardware = json.getJSONObject("hardware");
6366
ingestEndpoint.setText(hardware.getString("ingest_endpoint"));
6467
streamKey.setText(hardware.getString("stream_key"));
68+
String deviceId = (hardware.getString("device_id"));
69+
NetworkRequestManager nrm = new NetworkRequestManager(this, progressBar, networkResultView);
70+
emailButton.setOnClickListener(view1 -> {
71+
email(emailButton, nrm, deviceId,
72+
json1 -> {
73+
74+
},
75+
json1 -> {
76+
77+
});
78+
});
6579
errorTextView.setText("");
6680
}catch(JSONException e)
6781
{
@@ -94,6 +108,7 @@ protected void onCreate(Bundle savedInstanceState) {
94108
json1->{
95109
channelRegisterImageView.setImageDrawable(AppCompatResources.getDrawable(this, R.drawable.baseline_check_circle_outline_192));
96110
Account.getInstance().setHardware_id(hardwareId);
111+
errorTextView.setText("");
97112
},
98113
json1 ->{
99114
errorTextView.setText("Failed to connect to process request. Try again");
@@ -136,8 +151,7 @@ private void registerDevice(Button button, NetworkInterface success, NetworkInte
136151
});
137152
}
138153

139-
private void connectDevice(Button button, String device_id, NetworkInterface success, NetworkInterface fail)
140-
{
154+
private void connectDevice(Button button, String device_id, NetworkInterface success, NetworkInterface fail) {
141155
JSONObject jsonObject = new JSONObject(
142156
Map.of(
143157
"token", Account.getInstance().getTokenData().getValue(),
@@ -157,6 +171,26 @@ private void connectDevice(Button button, String device_id, NetworkInterface suc
157171
});
158172
}
159173

174+
private void email(Button button, NetworkRequestManager nrm, String device_id, NetworkInterface success, NetworkInterface fail)
175+
{
176+
JSONObject jsonObject = new JSONObject(
177+
Map.of(
178+
"token", Account.getInstance().getTokenData().getValue(),
179+
"device_id", device_id
180+
));
181+
button.setEnabled(false);
182+
nrm.Post(R.string.device_email_endpoint, jsonObject,
183+
json -> {
184+
button.setEnabled(true);
185+
success.action(json);
186+
},
187+
json -> {
188+
errorTextView.setText("Failed to connect to process request. Try again");
189+
button.setEnabled(true);
190+
fail.action(json);
191+
});
192+
}
193+
160194
public static boolean isNumeric(String strNum) {
161195
if (strNum == null) {
162196
return false;

Android/Layout_Version/app/src/main/java/com/example/layout_version/Network/NetworkRequestManager.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
import android.content.res.Resources;
1111
import android.os.Build;
1212
import android.view.View;
13+
import android.widget.ImageView;
1314
import android.widget.ProgressBar;
1415

16+
import androidx.appcompat.content.res.AppCompatResources;
1517
import androidx.core.app.ActivityCompat;
1618
import androidx.core.app.NotificationCompat;
1719
import androidx.core.app.NotificationManagerCompat;
@@ -38,18 +40,33 @@ public class NetworkRequestManager {
3840
private final RequestQueue mRequestQueue;
3941
private final Context context;
4042
private final ProgressBar progressBar;
43+
44+
private final ImageView resultView;
4145
public NetworkRequestManager(Context context)
4246
{
43-
this(context, null);
47+
this(context, null, null);
4448
}
4549

4650
public NetworkRequestManager(Context context, ProgressBar progressBar)
51+
{
52+
this(context, progressBar, null);
53+
}
54+
55+
public NetworkRequestManager(Context context, ImageView resultView)
56+
{
57+
this(context, null, resultView);
58+
}
59+
60+
public NetworkRequestManager(Context context, ProgressBar progressBar, ImageView resultView)
4761
{
4862
this.context = context;
4963
mRequestQueue = Volley.newRequestQueue(context);
5064
this.progressBar = progressBar;
5165
if(progressBar != null)
5266
progressBar.setVisibility(View.GONE);
67+
this.resultView = resultView;
68+
if(resultView != null)
69+
resultView.setVisibility(View.GONE);
5370
}
5471

5572
public void Post(int endpointID, JSONObject data, NetworkInterface success, NetworkInterface fail)
@@ -85,11 +102,18 @@ public void Request(String url, int method, JSONObject data, NetworkInterface su
85102
{
86103
if(progressBar != null)
87104
progressBar.setVisibility(View.VISIBLE);
105+
if(resultView != null)
106+
resultView.setVisibility(View.GONE);
88107
JsonObjectRequest jsonRequest = new JsonObjectRequest(method, url, data,
89108
json -> {
90109
success.action(json);
91110
if(progressBar != null)
92111
progressBar.setVisibility(View.GONE);
112+
if(resultView != null)
113+
{
114+
resultView.setImageDrawable(AppCompatResources.getDrawable(context, R.drawable.baseline_check_circle_outline_32));
115+
resultView.setVisibility(View.VISIBLE);
116+
}
93117
},
94118
error -> {
95119
NetworkResponse response = error.networkResponse;
@@ -106,6 +130,11 @@ public void Request(String url, int method, JSONObject data, NetworkInterface su
106130
}
107131
if(progressBar != null)
108132
progressBar.setVisibility(View.GONE);
133+
if(resultView != null)
134+
{
135+
resultView.setImageDrawable(AppCompatResources.getDrawable(context, R.drawable.baseline_highlight_off_24));
136+
resultView.setVisibility(View.VISIBLE);
137+
}
109138
}){
110139
};
111140

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="32dp" android:tint="@color/success"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="32dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M16.59,7.58L10,14.17l-3.59,-3.58L5,12l5,5 8,-8zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/>
5+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="32dp" android:tint="@color/error"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="32dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M14.59,8L12,10.59 9.41,8 8,9.41 10.59,12 8,14.59 9.41,16 12,13.41 14.59,16 16,14.59 13.41,12 16,9.41 14.59,8zM12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z"/>
5+
</vector>

Android/Layout_Version/app/src/main/res/layout/channel_information.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,28 @@
8787
app:layout_constraintHorizontal_bias="0.498"
8888
app:layout_constraintStart_toStartOf="parent"
8989
app:layout_constraintTop_toBottomOf="@+id/streamKeyTextView" />
90+
91+
<ImageView
92+
android:id="@+id/networkResultView"
93+
android:layout_width="wrap_content"
94+
android:layout_height="wrap_content"
95+
app:layout_constraintBottom_toBottomOf="@+id/emailButton"
96+
app:layout_constraintEnd_toEndOf="parent"
97+
app:layout_constraintHorizontal_bias="0.2"
98+
app:layout_constraintStart_toEndOf="@+id/emailButton"
99+
app:layout_constraintTop_toTopOf="@+id/emailButton"
100+
app:srcCompat="@drawable/baseline_check_circle_outline_32" />
101+
102+
<ProgressBar
103+
android:id="@+id/progressBar"
104+
style="?android:attr/progressBarStyle"
105+
android:layout_width="32dp"
106+
android:layout_height="32dp"
107+
app:layout_constraintBottom_toBottomOf="@+id/emailButton"
108+
app:layout_constraintEnd_toEndOf="parent"
109+
app:layout_constraintHorizontal_bias="0.2"
110+
app:layout_constraintStart_toEndOf="@+id/emailButton"
111+
app:layout_constraintTop_toTopOf="@+id/emailButton" />
90112
</androidx.constraintlayout.widget.ConstraintLayout>
91113

92114
</androidx.constraintlayout.widget.ConstraintLayout>

Android/Layout_Version/app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<string name="device_share_endpoint">/hardware/share</string>
1919
<string name="device_code_endpoint">/hardware/code</string>
2020
<string name="livestream_connect_endpoint">/account/livestream/device</string>
21+
<string name="device_email_endpoint">/account/email/device</string>
2122
<string name="device_register_url">https://cp0s049dll.execute-api.us-east-1.amazonaws.com/dev</string>
2223
<!-- TODO: Remove or change this placeholder text -->
2324
<string name="hello_blank_fragment">Hello blank fragment</string>

0 commit comments

Comments
 (0)