Compare commits

...

10 Commits

8 changed files with 108 additions and 0 deletions

View File

@ -116,6 +116,8 @@ public class MainActivity extends AppCompatActivity {
} else if (item.getItemId() == R.id.show_account_dialog) {
showAccountDialog();
return true;
} else if (item.getItemId() == R.id.issue_login_code) {
parentData.issueLoginCode().thenAccept((loginCode) -> runOnUiThread(() -> showLoginCodeDialog(loginCode)));
} else {
logger.warn("不明なアイテム: " + item.getItemId());
}
@ -156,6 +158,9 @@ public class MainActivity extends AppCompatActivity {
// manage_child_accountを削除
navigationView.getMenu().removeItem(R.id.manage_child_account);
// issue_login_codeを削除
navigationView.getMenu().removeItem(R.id.issue_login_code);
} else {
logger.info("Child mode is disabled!");
bottomNavigationView.getMenu().removeItem(R.id.feature_common_child_child_navigation);
@ -237,6 +242,19 @@ public class MainActivity extends AppCompatActivity {
.show();
}
private void showLoginCodeDialog(Integer loginCode) {
View view = getLayoutInflater().inflate(R.layout.parent_login_code_dialog_layout, null);
TextView loginCodeTextView = view.findViewById(R.id.loginCodeTextView);
// loginCodeをStringに変換して4桁 2つに分割してハイフンで繋げる
loginCodeTextView.setText(loginCode.toString().substring(0, 4) + "-" + loginCode.toString().substring(4));
new MaterialAlertDialogBuilder(this)
.setTitle("ログインコード")
.setView(view)
.setPositiveButton("閉じる", (dialog, which) -> dialog.dismiss())
.show();
}
private void showDebugDialog() {
ScrollView scrollView = new ScrollView(this);

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<TextView
android:id="@+id/loginCodeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="30dp"
android:paddingBottom="25dp"
android:textAppearance="@style/TextAppearance.AppCompat.Display3" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -10,6 +10,11 @@
android:icon="@drawable/manage_accounts_24px"
android:title="子供アカウントの管理" />
<item
android:id="@+id/issue_login_code"
android:icon="@drawable/password_24px"
android:title="Alexaログインコード発行" />
<!-- Divider -->
<item
android:id="@+id/divider"

View File

@ -32,4 +32,10 @@ public interface ParentData {
*/
CompletableFuture<Void> updateParent(ParentModel parent);
/**
* 親ユーザーログインコード発行
* @return ログインコード
*/
CompletableFuture<Integer> issueLoginCode();
}

View File

@ -10,6 +10,7 @@ import one.nem.kidshift.data.UserSettings;
import one.nem.kidshift.data.retrofit.KidShiftApiService;
import one.nem.kidshift.data.retrofit.model.parent.ParentInfoResponse;
import one.nem.kidshift.data.retrofit.model.parent.ParentRenameRequest;
import one.nem.kidshift.data.retrofit.model.parent.auth.ParentLoginCodeResponse;
import one.nem.kidshift.model.ParentModel;
import one.nem.kidshift.model.callback.ParentModelCallback;
import one.nem.kidshift.utils.KSLogger;
@ -74,4 +75,17 @@ public class ParentDataImpl implements ParentData {
}
}
@Override
public CompletableFuture<Integer> issueLoginCode() {
Call<ParentLoginCodeResponse> call = kidShiftApiService.issueParentLoginCode();
try {
ParentLoginCodeResponse response = call.execute().body();
if (response == null) {
return CompletableFuture.completedFuture(null);
}
return CompletableFuture.completedFuture(response.getCode());
} catch (Exception e) {
return CompletableFuture.completedFuture(null);
}
}
}

View File

@ -11,6 +11,7 @@ import one.nem.kidshift.data.retrofit.model.parent.ParentInfoResponse;
import one.nem.kidshift.data.retrofit.model.parent.ParentRenameRequest;
import one.nem.kidshift.data.retrofit.model.parent.auth.ParentAuthRequest;
import one.nem.kidshift.data.retrofit.model.parent.auth.ParentAuthResponse;
import one.nem.kidshift.data.retrofit.model.parent.auth.ParentLoginCodeResponse;
import one.nem.kidshift.data.retrofit.model.task.HistoryListResponse;
import one.nem.kidshift.data.retrofit.model.task.TaskAddRequest;
import one.nem.kidshift.data.retrofit.model.task.TaskListResponse;
@ -183,6 +184,14 @@ public interface KidShiftApiService {
@Headers(AuthorizationInterceptor.HEADER_PLACEHOLDER)
Call<ChildLoginCodeResponse> issueLoginCode(@Path("id") String id);
/**
* 保護者ログインコード発行
* @return ParentLoginCodeResponse
*/
@GET("/parent/issue")
@Headers(AuthorizationInterceptor.HEADER_PLACEHOLDER)
Call<ParentLoginCodeResponse> issueParentLoginCode();
@GET("/task/history/{childId}")
@Headers(AuthorizationInterceptor.HEADER_PLACEHOLDER)
Call<HistoryListResponse> getHistory(@Path("childId") String childId);

View File

@ -0,0 +1,20 @@
package one.nem.kidshift.data.retrofit.model.parent.auth;
public class ParentLoginCodeResponse {
private int code;
public ParentLoginCodeResponse(int code) {
this.code = code;
}
public ParentLoginCodeResponse() {
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
}

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M80,760L80,680L880,680L880,760L80,760ZM126,518L74,488L108,428L40,428L40,368L108,368L74,310L126,280L160,338L194,280L246,310L212,368L280,368L280,428L212,428L246,488L194,518L160,458L126,518ZM446,518L394,488L428,428L360,428L360,368L428,368L394,310L446,280L480,338L514,280L566,310L532,368L600,368L600,428L532,428L566,488L514,518L480,458L446,518ZM766,518L714,488L748,428L680,428L680,368L748,368L714,310L766,280L800,338L834,280L886,310L852,368L920,368L920,428L852,428L886,488L834,518L800,458L766,518Z"/>
</vector>