room値を拾う処理を実装 #8
|
@ -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;
|
||||||
|
|
||||||
|
@ -64,8 +63,7 @@ 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,6 +14,9 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import com.google.firebase.firestore.FirebaseFirestore;
|
import com.google.firebase.firestore.FirebaseFirestore;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
|
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
|
||||||
|
|
||||||
// ID作成のTextViewとImageView
|
// ID作成のTextViewとImageView
|
||||||
|
@ -68,8 +71,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
firestoreReception.getDocumentsByClassId(100);
|
firestoreReception.getDocumentsByClassId(100);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,9 +92,15 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
}
|
}
|
||||||
// ルート作成のクリック処理
|
// ルート作成のクリック処理
|
||||||
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) {
|
||||||
|
@ -101,6 +108,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
startActivity(toSubmission);
|
startActivity(toSubmission);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showUUIDYesNoDialog() {
|
private void showUUIDYesNoDialog() {
|
||||||
//ダイアログの表示
|
//ダイアログの表示
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
|
|
|
@ -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