update reordering

This commit is contained in:
Mohamed Nouffer
2022-09-23 18:40:17 +05:30
parent 5a183867bd
commit 904dd358f7
5 changed files with 150 additions and 39 deletions

View File

@ -235,6 +235,13 @@ class DestinationController extends GetxController {
}); });
} }
void deleteAllDestinations(){
DatabaseHelper db = DatabaseHelper.instance;
db.deleteAllDestinations().then((value){
PopulateDestinations();
});
}
// ---------- database ------------------/// // ---------- database ------------------///
void addDestinations(Destination dest){ void addDestinations(Destination dest){
@ -294,8 +301,11 @@ class DestinationController extends GetxController {
} }
void makeOrder(String locationId){ void makeOrder(Destination d, int dir){
DatabaseHelper db = DatabaseHelper.instance;
db.updateOrder(d, dir).then((value){
PopulateDestinations();
});
} }

View File

@ -39,14 +39,15 @@ class DestinationMapPage extends StatelessWidget {
} }
String getDisplaytext(Destination dp){ String getDisplaytext(Destination dp){
RegExp regex = RegExp(r'([.]*0)(?!.*\d)');
String txt = ""; String txt = "";
if(dp.cp! > 0){ if(dp.cp! > 0){
txt = "${dp.cp}"; txt = "${dp.cp.toString().replaceAll(regex, '')}";
if(dp.checkin_point != null && dp.checkin_point! > 0){ if(dp.checkin_point != null && dp.checkin_point! > 0){
txt = txt + "{${dp.checkin_point}}"; txt = txt + "{${dp.checkin_point.toString().replaceAll(regex, '')}}";
} }
if(dp.buy_point != null && dp.buy_point! > 0){ if(dp.buy_point != null && dp.buy_point! > 0){
txt = txt + "[${dp.buy_point}]"; txt = txt + "[${dp.buy_point.toString().replaceAll(regex, '')}]";
} }
} }
return txt; return txt;

View File

@ -70,9 +70,38 @@ class DatabaseHelper{
Database db = await instance.database; Database db = await instance.database;
var dest = await db.delete('destination', where: "location_id = ${location_id}"); var dest = await db.delete('destination', where: "location_id = ${location_id}");
int ret = dest > 0 ? dest : -1; int ret = dest > 0 ? dest : -1;
//after deleting set correct order
await setOrder();
return ret; return ret;
} }
Future<void>setOrder() async {
Database db = await instance.database;
var byOrder = await db.query('destination', orderBy: 'list_order');
List<Destination> des_db = byOrder.isNotEmpty
? byOrder.map((e) => Destination.fromMap(e)).toList() : [];
int order = 1;
for( Destination d in des_db){
Map<String, dynamic> row_target = {
"list_order": order
};
await db.update(
"destination",
row_target,
where: 'location_id = ?',
whereArgs: [d.location_id]
);
order += 1;
}
}
Future<void> deleteAllDestinations() async { Future<void> deleteAllDestinations() async {
Database db = await instance.database; Database db = await instance.database;
await db.delete('destination'); await db.delete('destination');
@ -117,6 +146,10 @@ class DatabaseHelper{
Database db = await instance.database; Database db = await instance.database;
var target = await db.query('destination', where: "list_order = ${d.list_order! + dir}"); var target = await db.query('destination', where: "list_order = ${d.list_order! + dir}");
var dest = await db.query('destination', where: "location_id = ${d.location_id}"); var dest = await db.query('destination', where: "location_id = ${d.location_id}");
print("--- target in db is ${target}");
print("--- destine in db is ${dest}");
if(target.isNotEmpty){ if(target.isNotEmpty){
List<Destination> target_indb = target.isNotEmpty List<Destination> target_indb = target.isNotEmpty
@ -130,9 +163,12 @@ class DatabaseHelper{
}; };
Map<String, dynamic> row_des = { Map<String, dynamic> row_des = {
"list_order": dest_indb[0].list_order "list_order": dest_indb[0].list_order! + dir
}; };
// print("--- target destination is ${target_indb[0].location_id}");
// print("--- destine destination is is ${dest_indb[0].location_id}");
await db.update( await db.update(
"destination", "destination",
row_target, row_target,

View File

@ -35,7 +35,13 @@ class StringValues extends Translations{
'select_travel_mode':'Select your travel mode', 'select_travel_mode':'Select your travel mode',
'walking':'Walking', 'walking':'Walking',
'driving': 'Driving', 'driving': 'Driving',
'transit': 'Transit' 'transit': 'Transit',
'are_you_sure_want_to_delete_all' : 'Are you sure want to delete all',
'all_added_destination_will_be_deleted' : 'All added destination will be deleted',
'confirm': 'Confirm',
'cancel': 'Cancel',
'all_destinations_are_deleted_successfully' : 'All destinations are deleted successfully',
'deleted': "Deleted"
}, },
'ja_JP': { 'ja_JP': {
'drawer_title':'ロゲイニング参加者はログイン するとチェックポイントが参照 できます', 'drawer_title':'ロゲイニング参加者はログイン するとチェックポイントが参照 できます',
@ -69,9 +75,15 @@ class StringValues extends Translations{
'rogaining_user_need_tosign_up': "ロゲイニング参加者はサインアップの必要はありません。", 'rogaining_user_need_tosign_up': "ロゲイニング参加者はサインアップの必要はありません。",
'add_location': '目的地選択', 'add_location': '目的地選択',
'select_travel_mode':'移動モードを選択してください', 'select_travel_mode':'移動モードを選択してください',
'walking':'ウォーキング', 'walking':'歩行',
'driving': '運転中', 'driving': '自動車利用',
'transit': 'トランジット' 'transit': '公共交通機関利用',
'are_you_sure_want_to_delete_all' : '本当にすべて削除しますか',
'all_added_destination_will_be_deleted' : '追加したすべての宛先が削除されます',
'confirm': '確認',
'cancel': 'キャンセル',
'all_destinations_are_deleted_successfully' : 'すべての宛先が正常に削除されました',
'deleted': "削除された"
}, },
}; };
} }

View File

@ -60,24 +60,57 @@ class DestinationWidget extends StatelessWidget {
} }
void moveUp() { void moveUp() {
for(Destination d in destinationController.destinations){ Destination? d = null;
// if(d.selected){ for(Destination ad in destinationController.destinations){
if(ad.selected == true){
// } d = ad;
break;
}
}
if(d != null){
print("--- selected destination is ${d.list_order}");
destinationController.makeOrder(d, -1);
} }
destinationController.destination_index_data.forEach((element) {
//print(element["index"]);
//int action_id = destinationController.destinations[element["index"]]["id"] as int;
//destinationController.makeOrder(action_id, (element["index"] as int) - 1, "up");
});
} }
void moveDown() { void moveDown() {
destinationController.destination_index_data.forEach((element) { Destination? d = null;
//print(element["index"]); for(Destination ad in destinationController.destinations){
//int action_id = destinationController.destinations[element["index"]]["id"] as int; if(ad.selected == true){
//destinationController.makeOrder(action_id, (element["index"] as int) + 1, "up"); d = ad;
}); break;
}
}
if(d != null){
print("--- selected destination is ${d.list_order}");
destinationController.makeOrder(d, 1);
}
}
void clearall(){
Get.defaultDialog(
title: "are_you_sure_want_to_delete_all".tr,
middleText: "all_added_destination_will_be_deleted".tr,
backgroundColor: Colors.blue.shade300,
titleStyle: TextStyle(color: Colors.white),
middleTextStyle: TextStyle(color: Colors.white),
textConfirm: "confirm".tr,
textCancel: "cancel".tr,
cancelTextColor: Colors.white,
confirmTextColor: Colors.blue,
buttonColor: Colors.white,
barrierDismissible: false,
radius: 10,
content: Column(
children: [
],
),
onConfirm: (){
destinationController.deleteAllDestinations();
Get.back();
Get.snackbar("deleted".tr, "all_destinations_are_deleted_successfully".tr);
}
);
} }
void interChange() { void interChange() {
@ -148,19 +181,33 @@ class DestinationWidget extends StatelessWidget {
}, },
onLongPress: (){ onLongPress: (){
Destination? match_element = null; for(Destination d in destinationController.destinations){
destinationController.currentSelectedDestinations.forEach((element) { if(destinationController.currentSelectedDestinations.length > 0){
if(element.location_id == destinationController.destinations[index].location_id){ if(destinationController.currentSelectedDestinations[0].location_id == destinationController.destinations[index].location_id){
match_element = element; destinationController.currentSelectedDestinations.clear();
print("---- fount ----");
destinationController.PopulateDestinations();
return; return;
} }
}); }
if(match_element != null){
destinationController.currentSelectedDestinations.remove(destinationController.destinations[index]);
} }
destinationController.currentSelectedDestinations.add(destinationController.destinations[index]); destinationController.currentSelectedDestinations.clear();
destinationController.currentSelectedDestinations.add(destinationController.destinations[index]);
// Destination? match_element = null;
// destinationController.currentSelectedDestinations.forEach((element) {
// if(element.location_id == destinationController.destinations[index].location_id){
// match_element = element;
// return;
// }
// });
// if(match_element != null){
// destinationController.currentSelectedDestinations.remove(destinationController.destinations[index]);
// }
// //destinationController.currentSelectedDestinations.clear();
// destinationController.currentSelectedDestinations.add(destinationController.destinations[index]);
destinationController.PopulateDestinations(); destinationController.PopulateDestinations();
@ -205,6 +252,11 @@ class DestinationWidget extends StatelessWidget {
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
IconButton(
icon:Icon(Icons.delete_forever),
//onPressed: (){doDelete();},
onPressed: clearall,
),
IconButton( IconButton(
icon:Icon(Icons.cancel), icon:Icon(Icons.cancel),
//onPressed: (){doDelete();}, //onPressed: (){doDelete();},
@ -212,16 +264,16 @@ class DestinationWidget extends StatelessWidget {
), ),
IconButton( IconButton(
icon:Icon(Icons.move_up), icon:Icon(Icons.move_up),
onPressed: destinationController.destination_index_data.length > 0 ? moveUp : null, onPressed: destinationController.currentSelectedDestinations.length > 0 ? moveUp : null,
), ),
IconButton( IconButton(
icon:Icon(Icons.move_down), icon:Icon(Icons.move_down),
onPressed: destinationController.destination_index_data.length > 0 ? moveDown : null, onPressed: destinationController.currentSelectedDestinations.length > 0 ? moveDown : null,
),
IconButton(
icon:Icon(Icons.sync),
onPressed: destinationController.destination_index_data.length == 2 ? interChange : null,
), ),
// IconButton(
// icon:Icon(Icons.sync),
// onPressed: destinationController.destination_index_data.length == 2 ? interChange : null,
// ),
], ],
), ),
) )