Skip to content

Commit 7dfdbbb

Browse files
committed
Fixed problem where device is created twice. Dismiss dialog after device connected
1 parent 6782d61 commit 7dfdbbb

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import com.example.layout_version.R;
1616

17-
public class CameraConnectDialog extends DialogFragment {
17+
public class CameraConnectDialog extends DialogFragment implements CameraConnectFragment.CameraShareInterface {
1818
@Override
1919
public View onCreateView(LayoutInflater inflater, ViewGroup container,
2020
Bundle savedInstanceState) {
@@ -46,4 +46,9 @@ public void onActivityCreated(Bundle savedInstanceState) {
4646
lp.width = dialogWidth;
4747
dialog.getWindow().setAttributes(lp);
4848
}
49+
50+
@Override
51+
public void action() {
52+
dismiss();
53+
}
4954
}

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

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

3+
import android.app.Activity;
34
import android.content.Context;
45
import android.os.Bundle;
56

67
import androidx.fragment.app.Fragment;
8+
import androidx.lifecycle.ViewModelProvider;
79

810
import android.util.Log;
911
import android.view.LayoutInflater;
@@ -14,6 +16,10 @@
1416
import android.widget.Toast;
1517

1618
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;
1723
import com.example.layout_version.Network.NetworkRequestManager;
1824
import com.example.layout_version.R;
1925

@@ -54,6 +60,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
5460
nrm.Post(R.string.device_code_endpoint, jsonObject,
5561
json -> {
5662
Toast.makeText(context, "Successfully connected device to account", Toast.LENGTH_SHORT).show();
63+
if(getParentFragment() instanceof CameraShareInterface)
64+
{
65+
((CameraShareInterface)getParentFragment()).action();
66+
StreamingViewModel streamingViewModel = new ViewModelProvider(requireActivity()).get(StreamingViewModel.class);
67+
StreamingListFragmentInterface.loadData(getContext(), streamingViewModel, Account.getInstance().getTokenData().getValue(), 4);
68+
}
5769
},
5870
json->{
5971
Toast.makeText(context, "Error", Toast.LENGTH_SHORT).show();
@@ -62,4 +74,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
6274

6375
return layout;
6476
}
77+
78+
interface CameraShareInterface{
79+
void action();
80+
}
6581
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,7 @@ public void Post(int endpointID, JSONObject data, NetworkInterface success, Netw
6464

6565
public void Post(String url, JSONObject data, NetworkInterface success, NetworkInterface fail)
6666
{
67-
Request(url, Request.Method.POST, data, success, fail);
68-
}
69-
70-
public void Put(String url, JSONObject data, NetworkInterface success, NetworkInterface fail)
71-
{
72-
Request(url, Request.Method.PUT, data, success, fail);
67+
Request(url, Request.Method.POST, data, success, fail, DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 4, DefaultRetryPolicy.DEFAULT_MAX_RETRIES);
7368
}
7469

7570
public void Put(int endpointID, JSONObject data, NetworkInterface success, NetworkInterface fail)
@@ -78,10 +73,15 @@ public void Put(int endpointID, JSONObject data, NetworkInterface success, Netwo
7873
String url = resource.getString(R.string.db_base_url)
7974
+ resource.getString(R.string.db_stage)
8075
+ resource.getString(endpointID);
81-
Request(url, Request.Method.PUT, data, success, fail);
76+
Put(url, data, success, fail);
77+
}
78+
79+
public void Put(String url, JSONObject data, NetworkInterface success, NetworkInterface fail)
80+
{
81+
Request(url, Request.Method.PUT, data, success, fail, DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 5, 0);
8282
}
8383

84-
public void Request(String url, int method, JSONObject data, NetworkInterface success, NetworkInterface fail)
84+
public void Request(String url, int method, JSONObject data, NetworkInterface success, NetworkInterface fail, int timeout, int retry)
8585
{
8686
if(progressBar != null)
8787
progressBar.setVisibility(View.VISIBLE);
@@ -110,8 +110,8 @@ public void Request(String url, int method, JSONObject data, NetworkInterface su
110110
};
111111

112112
jsonRequest.setRetryPolicy(new DefaultRetryPolicy(
113-
DefaultRetryPolicy.DEFAULT_TIMEOUT_MS,
114-
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
113+
timeout,
114+
retry,
115115
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
116116
mRequestQueue.add(jsonRequest);
117117
}

Android/Layout_Version/app/src/main/java/com/example/layout_version/SenderStream/LiveStreamActivity.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ protected void onCreate(Bundle savedInstanceState) {
7272
{
7373
setupBroadcastSession();
7474
}
75-
7675
}
7776

7877
public void setupBroadcastSession()

0 commit comments

Comments
 (0)