room値を拾う処理を実装
This commit is contained in:
parent
a3dd2f922d
commit
6fc1e6daa5
|
@ -1,7 +1,7 @@
|
||||||
package com.example.oplogy;
|
package com.example.oplogy;
|
||||||
|
|
||||||
import androidx.room.Database;
|
import androidx.room.Database;
|
||||||
import androidx.room.RoomDatabase;
|
import androidx.room.RoomDatabase;
|
||||||
import androidx.room.TypeConverters;
|
|
||||||
|
|
||||||
@Database(entities = {SetUpTable.class}, version = 1)
|
@Database(entities = {SetUpTable.class}, version = 1)
|
||||||
public abstract class AppDatabase extends RoomDatabase {
|
public abstract class AppDatabase extends RoomDatabase {
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
package com.example.oplogy;
|
package com.example.oplogy;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.room.Room;
|
||||||
|
|
||||||
import com.google.firebase.Timestamp;
|
import com.google.firebase.Timestamp;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
@ -9,11 +12,22 @@ import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
|
||||||
public class CreateRoot {
|
public class CreateRoot {
|
||||||
public void receiveData(List<MyDataClass> myDataList) {
|
private Context context;
|
||||||
|
private AppDatabase db;
|
||||||
|
|
||||||
|
public CreateRoot(MainActivity activity) {
|
||||||
|
this.context = activity;
|
||||||
|
this.db = Room.databaseBuilder(activity.getApplicationContext(), AppDatabase.class, "SetUpTable").build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void receiveData(List<MyDataClass> myDataList) {
|
||||||
for (int i = 0; i < myDataList.size(); i++) {
|
for (int i = 0; i < myDataList.size(); i++) {
|
||||||
|
//希望時間帯の終了時刻から開始時刻を引いて希望時間帯の長さ(timezone)に入れる
|
||||||
MyDataClass data = myDataList.get(i);
|
MyDataClass data = myDataList.get(i);
|
||||||
List<Timestamp> firstDay = data.getFirstDay();
|
List<Timestamp> firstDay = data.getFirstDay();
|
||||||
Timestamp startTime = firstDay.get(0);
|
Timestamp startTime = firstDay.get(0);
|
||||||
|
@ -21,6 +35,7 @@ public class CreateRoot {
|
||||||
Long timezone = endTime.getSeconds() - startTime.getSeconds();
|
Long timezone = endTime.getSeconds() - startTime.getSeconds();
|
||||||
data.setTimezone(timezone);
|
data.setTimezone(timezone);
|
||||||
|
|
||||||
|
//TimeStampを日付に変換
|
||||||
Date startDate = new Date(startTime.getSeconds() * 1000);
|
Date startDate = new Date(startTime.getSeconds() * 1000);
|
||||||
Date endDate = new Date(endTime.getSeconds() * 1000);
|
Date endDate = new Date(endTime.getSeconds() * 1000);
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
@ -37,7 +52,7 @@ public class CreateRoot {
|
||||||
Log.d("CreateRoot", "(index: " + i + ") startDate: " + myDataList.get(i).getStartDateString());
|
Log.d("CreateRoot", "(index: " + i + ") startDate: " + myDataList.get(i).getStartDateString());
|
||||||
Log.d("CreateRoot", "(index: " + i + ") data: " + myDataList.get(i));
|
Log.d("CreateRoot", "(index: " + i + ") data: " + myDataList.get(i));
|
||||||
}
|
}
|
||||||
// timezoneを比較するComparatorを作成
|
// timezoneを比較するComparator→timezoneが短い順に並べる
|
||||||
Comparator<MyDataClass> comparator = new Comparator<MyDataClass>() {
|
Comparator<MyDataClass> comparator = new Comparator<MyDataClass>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(MyDataClass data1, MyDataClass data2) {
|
public int compare(MyDataClass data1, MyDataClass data2) {
|
||||||
|
@ -51,6 +66,17 @@ public class CreateRoot {
|
||||||
Log.d("CreateRoot", "(index: " + i + ") timezone: " + myDataList.get(i).getTimezone());
|
Log.d("CreateRoot", "(index: " + i + ") timezone: " + myDataList.get(i).getTimezone());
|
||||||
Log.d("CreateRoot", "(index: " + i + ") startDate: " + myDataList.get(i).getStartDateString());
|
Log.d("CreateRoot", "(index: " + i + ") startDate: " + myDataList.get(i).getStartDateString());
|
||||||
Log.d("CreateRoot", "(index: " + i + ") data: " + myDataList.get(i));
|
Log.d("CreateRoot", "(index: " + i + ") data: " + myDataList.get(i));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
|
executor.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
SetUpTableDao setUpTableDao = db.setUpTableDao();
|
||||||
|
String startTime=setUpTableDao.getStartTime();
|
||||||
|
Log.d("CreateRoot", "開始時間" + startTime);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,7 +11,6 @@ import com.google.firebase.firestore.QueryDocumentSnapshot;
|
||||||
import com.google.firebase.firestore.QuerySnapshot;
|
import com.google.firebase.firestore.QuerySnapshot;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -24,7 +23,7 @@ public class FirestoreReception {
|
||||||
}
|
}
|
||||||
|
|
||||||
//firestoreから受け取ったデータを束ねるためのマップ
|
//firestoreから受け取ったデータを束ねるためのマップ
|
||||||
public List<MyDataClass>myDataList = new ArrayList<>();
|
public List<MyDataClass> myDataList = new ArrayList<>();
|
||||||
|
|
||||||
//ClassIdを引数にデータの作成を行う
|
//ClassIdを引数にデータの作成を行う
|
||||||
public void getDocumentsByClassId(int classId) {
|
public void getDocumentsByClassId(int classId) {
|
||||||
|
@ -61,11 +60,10 @@ public class FirestoreReception {
|
||||||
|
|
||||||
|
|
||||||
//取得したデータをログ表示
|
//取得したデータをログ表示
|
||||||
for(MyDataClass data :myDataList){
|
for (MyDataClass data : myDataList) {
|
||||||
Log.i("FirestoreReceptiond", "data: " + data.toString());
|
Log.i("FirestoreReceptiond", "data: " + data.toString());
|
||||||
}
|
}
|
||||||
CreateRoot createRoot=new CreateRoot();
|
|
||||||
createRoot.receiveData(myDataList);
|
|
||||||
} else {
|
} else {
|
||||||
Log.w("FirestoreReceptiond", "Error getting documents.", task.getException());
|
Log.w("FirestoreReceptiond", "Error getting documents.", task.getException());
|
||||||
}
|
}
|
||||||
|
@ -73,4 +71,12 @@ public class FirestoreReception {
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMyDataListSize() {
|
||||||
|
return myDataList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MyDataClass> getMyDataList() {
|
||||||
|
return myDataList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,10 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import com.google.firebase.firestore.FirebaseFirestore;
|
import com.google.firebase.firestore.FirebaseFirestore;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
|
||||||
|
|
||||||
// ID作成のTextViewとImageView
|
// ID作成のTextViewとImageView
|
||||||
private TextView creatUUID;
|
private TextView creatUUID;
|
||||||
|
@ -68,39 +71,44 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
firestoreReception.getDocumentsByClassId(100);
|
firestoreReception.getDocumentsByClassId(100);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// クリック処理
|
// クリック処理
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
// ID作成のクリック処理
|
// ID作成のクリック処理
|
||||||
if(view == creatUUID){
|
if (view == creatUUID) {
|
||||||
imageUuid.setImageResource(R.drawable.ischecked_uuid);
|
imageUuid.setImageResource(R.drawable.ischecked_uuid);
|
||||||
showUUIDYesNoDialog();//UUIDを表示するかのダイアログ
|
showUUIDYesNoDialog();//UUIDを表示するかのダイアログ
|
||||||
|
|
||||||
}
|
}
|
||||||
// セットアップのクリック処理
|
// セットアップのクリック処理
|
||||||
if(view == setUp){
|
if (view == setUp) {
|
||||||
imageSetup.setImageResource(R.drawable.ischecked_uuid);
|
imageSetup.setImageResource(R.drawable.ischecked_uuid);
|
||||||
Intent toSetup = new Intent(MainActivity.this,SetUpActivity.class);
|
Intent toSetup = new Intent(MainActivity.this, SetUpActivity.class);
|
||||||
startActivity(toSetup);
|
startActivity(toSetup);
|
||||||
|
|
||||||
}
|
}
|
||||||
// ルート作成のクリック処理
|
// ルート作成のクリック処理
|
||||||
if(view == root){
|
if (view == root) {
|
||||||
|
//CreateRootにmyDataListを渡す
|
||||||
imageRoot.setImageResource(R.drawable.pin);
|
imageRoot.setImageResource(R.drawable.pin);
|
||||||
Intent toRoot = new Intent(MainActivity.this,Maps.class);
|
List<MyDataClass> myDataList = firestoreReception.getMyDataList();
|
||||||
|
CreateRoot createRoot = new CreateRoot(MainActivity.this);
|
||||||
|
createRoot.receiveData(myDataList);
|
||||||
|
Intent toRoot = new Intent(MainActivity.this, CreateRoot.class);
|
||||||
|
toRoot.putExtra("myDataList", (ArrayList<MyDataClass>) myDataList);
|
||||||
startActivity(toRoot);
|
startActivity(toRoot);
|
||||||
|
|
||||||
}
|
}
|
||||||
// 提出状況のクリック処理
|
// 提出状況のクリック処理
|
||||||
if(view == submission){
|
if (view == submission) {
|
||||||
Intent toSubmission = new Intent(MainActivity.this,SubmissionActivity.class);
|
Intent toSubmission = new Intent(MainActivity.this, SubmissionActivity.class);
|
||||||
startActivity(toSubmission);
|
startActivity(toSubmission);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showUUIDYesNoDialog() {
|
private void showUUIDYesNoDialog() {
|
||||||
//ダイアログの表示
|
//ダイアログの表示
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
|
@ -119,7 +127,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
Log.d("DialogNO","DialogでNoが選ばれました");
|
Log.d("DialogNO", "DialogでNoが選ばれました");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.show();
|
builder.show();
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
package com.example.oplogy;
|
package com.example.oplogy;
|
||||||
|
|
||||||
import androidx.room.Dao;
|
import androidx.room.Dao;
|
||||||
import androidx.room.Insert;
|
import androidx.room.Insert;
|
||||||
import androidx.room.Query;
|
import androidx.room.Query;
|
||||||
import androidx.room.Update;
|
import androidx.room.Update;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
public interface SetUpTableDao {
|
public interface SetUpTableDao {
|
||||||
@Insert
|
@Insert
|
||||||
|
@ -16,4 +15,9 @@ public interface SetUpTableDao {
|
||||||
//名前が一致しているかの確認
|
//名前が一致しているかの確認
|
||||||
@Query("SELECT * FROM SetUpTable WHERE teacherName = :name LIMIT 1")
|
@Query("SELECT * FROM SetUpTable WHERE teacherName = :name LIMIT 1")
|
||||||
SetUpTable findByName(String name);
|
SetUpTable findByName(String name);
|
||||||
|
//開始時間と終了時間の取得
|
||||||
|
@Query("SELECT startTime FROM SetUpTable")
|
||||||
|
String getStartTime();
|
||||||
|
@Query("SELECT endTime FROM SetUpTable")
|
||||||
|
String getEndTime();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user