diff --git a/.idea/androidTestResultsUserPreferences.xml b/.idea/androidTestResultsUserPreferences.xml new file mode 100644 index 0000000..8e8835f --- /dev/null +++ b/.idea/androidTestResultsUserPreferences.xml @@ -0,0 +1,22 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml index d41abf1..ba79e02 100644 --- a/.idea/deploymentTargetSelector.xml +++ b/.idea/deploymentTargetSelector.xml @@ -13,6 +13,17 @@ + + \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..fdf8d99 --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 196d470..ba81945 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/app/build.gradle b/app/build.gradle index 005e609..bf69f43 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,6 @@ plugins { alias(libs.plugins.android.application) + alias(libs.plugins.jetbrains.kotlin.android) } android { @@ -14,6 +15,9 @@ versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + vectorDrawables { + useSupportLibrary true + } } buildTypes { @@ -28,6 +32,18 @@ } buildFeatures { viewBinding true + compose true + } + kotlinOptions { + jvmTarget = '1.8' + } + composeOptions { + kotlinCompilerExtensionVersion '1.5.1' + } + packaging { + resources { + excludes += '/META-INF/{AL2.0,LGPL2.1}' + } } } @@ -39,6 +55,13 @@ implementation libs.constraintlayout implementation libs.legacy.support.v4 implementation libs.recyclerview + implementation libs.lifecycle.runtime.ktx + implementation libs.activity.compose + implementation platform(libs.compose.bom) + implementation libs.ui + implementation libs.ui.graphics + implementation libs.ui.tooling.preview + implementation libs.material3 testImplementation libs.junit androidTestImplementation libs.ext.junit androidTestImplementation libs.espresso.core @@ -46,4 +69,8 @@ implementation libs.retrofit22 implementation libs.retrofit23 implementation libs.retrofit24 + androidTestImplementation platform(libs.compose.bom) + androidTestImplementation libs.ui.test.junit4 + debugImplementation libs.ui.tooling + debugImplementation libs.ui.test.manifest } \ No newline at end of file diff --git a/app/src/androidTest/java/com/example/citrusclient/CalendarTest.java b/app/src/androidTest/java/com/example/citrusclient/CalendarTest.java new file mode 100644 index 0000000..43cb6b4 --- /dev/null +++ b/app/src/androidTest/java/com/example/citrusclient/CalendarTest.java @@ -0,0 +1,27 @@ +package com.example.citrusclient; + +import static androidx.compose.ui.semantics.SemanticsPropertiesKt.onClick; +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.matcher.ViewMatchers.withId; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.core.app.ActivityScenario; + +import com.example.citrusclient.views.TestActivity; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +public class CalendarTest { + + @Test + public void testCalendar(){ + try(ActivityScenario scenario = ActivityScenario.launch(TestActivity.class)){ + onView(withId(R.id.otherRbBoth)).perform(click()); + System.out.println("helel"); + } + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3599197..a437b60 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,9 @@ - + + + + tools:targetApi="31"> + - - + android:exported="false" /> + android:exported="false" /> diff --git a/app/src/main/java/com/example/citrusclient/views/CalendarFragment.java b/app/src/main/java/com/example/citrusclient/views/CalendarFragment.java index 8e0360a..3317509 100644 --- a/app/src/main/java/com/example/citrusclient/views/CalendarFragment.java +++ b/app/src/main/java/com/example/citrusclient/views/CalendarFragment.java @@ -275,7 +275,7 @@ createBook.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - ((MainActivity) getActivity()).showFragment(new CreateScheduleFragment()); + ((MainActivity) getActivity()).showFragment(new CreateScheduleFragment(year, month, day)); } }); @@ -351,9 +351,15 @@ String[][] daysString = calendarString(firstDayOfWeek, prevMonthDay, lastDay); citrus.setCurDay(Integer.parseInt(daysString[ii][jj])); if(ii == 0 && Integer.parseInt(daysString[ii][jj]) > 8) { - citrus.setCurMonth(month - 1); + if(month == 1) { + month = 13; + citrus.setCurMonth(month - 1); + } } else if (ii >= 4 && Integer.parseInt(daysString[ii][jj]) < 25) { - citrus.setCurMonth(month + 1); + if(month == 12) { + month = 0; + citrus.setCurMonth(month + 1); + } } ((MainActivity) getActivity()).showFragment(new HomeFragment()); } @@ -477,7 +483,7 @@ @NonNull @Override public MyScheduleViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.a_calendar_schedule, parent, false); + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.other_calendar_schedule, parent, false); return new MyScheduleViewHolder(view); } diff --git a/app/src/main/java/com/example/citrusclient/views/OtherCalendarFragment.java b/app/src/main/java/com/example/citrusclient/views/OtherCalendarFragment.java index e03be33..133a209 100644 --- a/app/src/main/java/com/example/citrusclient/views/OtherCalendarFragment.java +++ b/app/src/main/java/com/example/citrusclient/views/OtherCalendarFragment.java @@ -62,25 +62,9 @@ private TableRow[] tableRows = new TableRow[6]; public OtherCalendarFragment() { - // Required empty public constructor - } - - /** - * Use this factory method to create a new instance of - * this fragment using the provided parameters. - * - * @param param1 Parameter 1. - * @param param2 Parameter 2. - * @return A new instance of fragment ScheduleFragment. - */ - // TODO: Rename and change types and number of parameters - public static CalendarFragment newInstance(String param1, String param2) { - CalendarFragment fragment = new CalendarFragment(); - Bundle args = new Bundle(); - args.putString(ARG_PARAM1, param1); - args.putString(ARG_PARAM2, param2); - fragment.setArguments(args); - return fragment; + Calendar calendar = Calendar.getInstance(); + year = calendar.get(Calendar.YEAR); //現在の年 + month = calendar.get(Calendar.MONTH) + 1; //現在の月 } @Override @@ -92,7 +76,7 @@ } scheduleViewModel = new ViewModelProvider(this).get(ScheduleViewModel.class); - booksViewModel = new ViewModelProvider(this).get(BooksViewModel.class); + todosViewModel = new ViewModelProvider(this).get(TodosViewModel.class); schedules = new HashMap<>(); @@ -102,11 +86,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_calendar, container, false); + return inflater.inflate(R.layout.fragment_other_calendar, container, false); } - BooksViewModel booksViewModel; + private List scheduleList; ScheduleViewModel scheduleViewModel; TodosViewModel todosViewModel; @@ -180,7 +164,8 @@ Citrus citrus = (Citrus)(getActivity().getApplication()); String token = citrus.getToken(); - String accountId = citrus.getAccountId(); + String accountId = citrus.getCurLookingAccountId(); + int bookId = citrus.getCurLookingBookId(); todos = new HashMap<>(); schedules = new HashMap<>(); @@ -194,26 +179,7 @@ } }); - booksViewModel.getBookLiveData().observe(getViewLifecycleOwner(), new Observer>() { - @Override - public void onChanged(HashMap integerBookHashMap) { - books = integerBookHashMap; - if(books != null) { - TextView curMonth = view.findViewById(R.id.otherMonth); - if(todos != null) { - todos.clear(); - } else { - todos = new HashMap<>(); - } - for(int bookId:books.keySet()){ - todosViewModel.loadTodosByMonth(accountId, bookId, year, month, token); - } - - updateCalendar(curMonth); - } - } - }); todosViewModel.getTodosByMonthLiveData().observe(getViewLifecycleOwner(), new Observer>>() { @Override @@ -231,15 +197,15 @@ } }); - booksViewModel.loadBooks(accountId, token); tableLayout = view.findViewById(R.id.calendarlayout); - Calendar calendar = Calendar.getInstance(); - year = calendar.get(Calendar.YEAR); //現在の年 - month = calendar.get(Calendar.MONTH) + 1; //現在の月 +// Calendar calendar = Calendar.getInstance(); +// year = calendar.get(Calendar.YEAR); //現在の年 +// month = calendar.get(Calendar.MONTH) + 1; //現在の月 - scheduleViewModel.updateSchedulesByMonth(accountId, year, month, token); + scheduleViewModel.updateSchedulesByMonthAndBookId(accountId, year, month, token, bookId); + todosViewModel.loadTodosByMonth(accountId, bookId, year, month, token); //現在の月の最後の日付を取得 YearMonth yearMonth = YearMonth.of(year, month); @@ -258,16 +224,9 @@ Button nextMonth = view.findViewById(R.id.otherNextMonth); Button prevMonth = view.findViewById(R.id.otherPrevMonth); - FloatingActionButton createBook = view.findViewById(R.id.floatingActionButton); TextView curMonth = view.findViewById(R.id.otherMonth); curMonth.setText(year + "年" + month + "月"); - createBook.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - ((MainActivity) getActivity()).showFragment(new CreateScheduleFragment()); - } - }); //カレンダーの次の月を表示 nextMonth.setOnClickListener(new View.OnClickListener() { @@ -278,7 +237,8 @@ month = 1; year++; } - scheduleViewModel.updateSchedulesByMonth(accountId, year, month, token); + scheduleViewModel.updateSchedulesByMonthAndBookId(accountId, year, month, token, bookId); + todosViewModel.loadTodosByMonth(accountId, bookId, year, month, token); } }); @@ -291,17 +251,24 @@ month = 12; year--; } - scheduleViewModel.updateSchedulesByMonth(accountId, year, month, token); + scheduleViewModel.updateSchedulesByMonthAndBookId(accountId, year, month, token, bookId); + todosViewModel.loadTodosByMonth(accountId, bookId, year, month, token); } }); view.findViewById(R.id.otherRbTodo).setOnClickListener(view1 -> { + scheduleViewModel.updateSchedulesByMonthAndBookId(accountId, year, month, token, bookId); + todosViewModel.loadTodosByMonth(accountId, bookId, year, month, token); updateCalendar(curMonth); }); view.findViewById(R.id.otherRbSchedule).setOnClickListener(view1 -> { + scheduleViewModel.updateSchedulesByMonthAndBookId(accountId, year, month, token, bookId); + todosViewModel.loadTodosByMonth(accountId, bookId, year, month, token); updateCalendar(curMonth); }); view.findViewById(R.id.otherRbBoth).setOnClickListener(view1 -> { + scheduleViewModel.updateSchedulesByMonthAndBookId(accountId, year, month, token, bookId); + todosViewModel.loadTodosByMonth(accountId, bookId, year, month, token); updateCalendar(curMonth); }); @@ -374,6 +341,7 @@ int one = 0; RadioGroup selectButton = getView().findViewById(R.id.otherSelectButton); + for(int i = 0; i < 6; i++) { TableRow tableRow = (TableRow) tableLayout.getChildAt(i); for(int j = 0; j < 7; j++) { @@ -449,7 +417,7 @@ @NonNull @Override public OtherScheduleViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.a_calendar_schedule, parent, false); + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.other_calendar_schedule, parent, false); return new OtherScheduleViewHolder(view); } diff --git a/app/src/main/java/com/example/citrusclient/views/TestActivity.java b/app/src/main/java/com/example/citrusclient/views/TestActivity.java new file mode 100644 index 0000000..ab77db7 --- /dev/null +++ b/app/src/main/java/com/example/citrusclient/views/TestActivity.java @@ -0,0 +1,32 @@ +package com.example.citrusclient.views; + +import android.os.Bundle; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +import com.example.citrusclient.R; + +import com.example.citrusclient.Citrus; + +public class TestActivity extends AppCompatActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_test); + + Citrus citrus = (Citrus)getApplication(); + citrus.setCurLookingAccountId("tako"); + citrus.setCurLookingBookId(2); + + + if (savedInstanceState == null) { + getSupportFragmentManager().beginTransaction() + .replace(R.id.fragment_container, new OtherCalendarFragment()) + .commit(); + } + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_test.xml b/app/src/main/res/layout/activity_test.xml new file mode 100644 index 0000000..a9ee9c5 --- /dev/null +++ b/app/src/main/res/layout/activity_test.xml @@ -0,0 +1,5 @@ + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b2b7d8f..2bff954 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -3,4 +3,5 @@ Hello blank fragment 本を選択してください + TestActivity \ No newline at end of file diff --git a/build.gradle b/build.gradle index 565f8c2..bd4e7d9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,5 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { alias(libs.plugins.android.application) apply false + alias(libs.plugins.jetbrains.kotlin.android) apply false } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2988cd9..c2e847c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,6 +13,10 @@ constraintlayout = "2.1.4" legacySupportV4 = "1.0.0" recyclerview = "1.3.0" +kotlin = "1.9.0" +lifecycleRuntimeKtx = "2.6.1" +activityCompose = "1.9.0" +composeBom = "2023.08.00" [libraries] junit = { group = "junit", name = "junit", version.ref = "junit" } @@ -28,7 +32,18 @@ constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" } legacy-support-v4 = { group = "androidx.legacy", name = "legacy-support-v4", version.ref = "legacySupportV4" } recyclerview = { group = "androidx.recyclerview", name = "recyclerview", version.ref = "recyclerview" } +lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" } +activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" } +compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" } +ui = { group = "androidx.compose.ui", name = "ui" } +ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" } +ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" } +ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" } +ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" } +ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" } +material3 = { group = "androidx.compose.material3", name = "material3" } [plugins] android-application = { id = "com.android.application", version.ref = "agp" } +jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }