|
3 | 3 | import android.content.Context; |
4 | 4 | import android.net.Uri; |
5 | 5 | import android.os.Bundle; |
| 6 | +import android.util.Log; |
6 | 7 | import android.view.LayoutInflater; |
7 | 8 | import android.view.View; |
8 | 9 | import android.view.ViewGroup; |
| 10 | +import android.widget.Button; |
| 11 | +import android.widget.EditText; |
9 | 12 | import android.widget.FrameLayout; |
10 | 13 | import android.widget.ImageButton; |
11 | 14 | import android.widget.TextView; |
| 15 | +import android.widget.Toast; |
12 | 16 |
|
13 | 17 | import androidx.annotation.NonNull; |
14 | 18 | import androidx.annotation.Nullable; |
|
23 | 27 | import com.example.layout_version.MainTab.Streaming.Recorder.Recorder; |
24 | 28 | import com.example.layout_version.MainTab.Streaming.Recorder.RecordingState; |
25 | 29 | import com.example.layout_version.MainTab.Streaming.Recorder.RecordingStateChangeListener; |
| 30 | +import com.example.layout_version.Network.NetworkRequestManager; |
26 | 31 | import com.example.layout_version.R; |
27 | 32 |
|
| 33 | +import org.json.JSONException; |
| 34 | +import org.json.JSONObject; |
| 35 | + |
| 36 | +import java.util.Map; |
| 37 | + |
28 | 38 | public class StreamingFragment extends StateFragment<RecordingState> { |
29 | 39 | private Context context; |
30 | 40 | private StreamingViewModel streamingViewModel; |
@@ -153,6 +163,55 @@ public void showOptions() |
153 | 163 | public void showShareDialog() |
154 | 164 | { |
155 | 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 | + |
156 | 215 | new AlertDialog.Builder(getActivity()) |
157 | 216 | .setView(view) |
158 | 217 | .show(); |
|
0 commit comments