Skip to content

Commit 241901a

Browse files
committed
Camera share dialog show function and layout done
1 parent 69733db commit 241901a

File tree

3 files changed

+65
-6
lines changed

3 files changed

+65
-6
lines changed

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
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;
@@ -23,8 +27,14 @@
2327
import com.example.layout_version.MainTab.Streaming.Recorder.Recorder;
2428
import com.example.layout_version.MainTab.Streaming.Recorder.RecordingState;
2529
import com.example.layout_version.MainTab.Streaming.Recorder.RecordingStateChangeListener;
30+
import com.example.layout_version.Network.NetworkRequestManager;
2631
import com.example.layout_version.R;
2732

33+
import org.json.JSONException;
34+
import org.json.JSONObject;
35+
36+
import java.util.Map;
37+
2838
public class StreamingFragment extends StateFragment<RecordingState> {
2939
private Context context;
3040
private StreamingViewModel streamingViewModel;
@@ -153,6 +163,55 @@ public void showOptions()
153163
public void showShareDialog()
154164
{
155165
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+
156215
new AlertDialog.Builder(getActivity())
157216
.setView(view)
158217
.show();

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99
android:layout_width="300dp"
1010
android:layout_height="240dp"
1111
android:layout_margin="30dp"
12-
android:layout_marginTop="30dp"
1312
app:layout_constraintBottom_toBottomOf="parent"
1413
app:layout_constraintEnd_toEndOf="parent"
15-
app:layout_constraintHorizontal_bias="0.504"
1614
app:layout_constraintStart_toStartOf="parent"
1715
app:layout_constraintTop_toBottomOf="@+id/constraintLayout6">
1816

@@ -36,7 +34,7 @@
3634
app:layout_constraintTop_toTopOf="parent" />
3735

3836
<TextView
39-
android:id="@+id/textView8"
37+
android:id="@+id/codeTextView"
4038
android:layout_width="0dp"
4139
android:layout_height="wrap_content"
4240
android:layout_marginStart="15dp"
@@ -62,7 +60,7 @@
6260
app:layout_constraintBottom_toBottomOf="parent"
6361
app:layout_constraintEnd_toEndOf="parent"
6462
app:layout_constraintStart_toEndOf="@+id/imageView5"
65-
app:layout_constraintTop_toBottomOf="@+id/textView8" />
63+
app:layout_constraintTop_toBottomOf="@+id/codeTextView" />
6664

6765
<TextView
6866
android:id="@+id/textView9"
@@ -128,7 +126,7 @@
128126
app:layout_constraintTop_toTopOf="parent" />
129127

130128
<EditText
131-
android:id="@+id/textView18"
129+
android:id="@+id/codeEdit"
132130
android:layout_width="0dp"
133131
android:layout_height="wrap_content"
134132
android:layout_marginStart="15dp"
@@ -155,7 +153,7 @@
155153
app:layout_constraintBottom_toBottomOf="parent"
156154
app:layout_constraintEnd_toEndOf="parent"
157155
app:layout_constraintStart_toEndOf="@+id/imageView15"
158-
app:layout_constraintTop_toBottomOf="@+id/textView18" />
156+
app:layout_constraintTop_toBottomOf="@+id/codeEdit" />
159157

160158
<TextView
161159
android:id="@+id/textView19"

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<string name="file_all_endpoint">/file/all</string>
1616
<string name="hardware_delete_endpoint">/hardware/delete</string>
1717
<string name="file_delete_endpoint">/file/delete</string>
18+
<string name="device_share_endpoint">/hardware/share</string>
19+
<string name="device_code_endpoint">/hardware/code</string>
1820
<!-- TODO: Remove or change this placeholder text -->
1921
<string name="hello_blank_fragment">Hello blank fragment</string>
2022
<string name="streaming_offline">Offline</string>

0 commit comments

Comments
 (0)