From 37aaeacdcdefb193e6119db2b4943348805cfeb3 Mon Sep 17 00:00:00 2001 From: AlexisTabin Date: Wed, 20 May 2020 15:11:26 +0200 Subject: [PATCH 01/41] Extract List Offline Region and Download Region dialogs in Fragments --- .../java/ch/epfl/sdp/ui/maps/offline/OfflineManagerActivity.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/ch/epfl/sdp/ui/maps/offline/OfflineManagerActivity.kt b/app/src/main/java/ch/epfl/sdp/ui/maps/offline/OfflineManagerActivity.kt index 9a555290c..e8e299ad0 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/maps/offline/OfflineManagerActivity.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/maps/offline/OfflineManagerActivity.kt @@ -5,6 +5,7 @@ import android.view.View import android.widget.Button import android.widget.ProgressBar import android.widget.Toast +import ch.epfl.sdp.MainApplication import ch.epfl.sdp.R import ch.epfl.sdp.map.MapUtils import ch.epfl.sdp.map.offline.DownloadProgressBarUtils.downloadingInProgress From c2a9facd87c55acfa852b8821ae425732c5a0025 Mon Sep 17 00:00:00 2001 From: Dorian Date: Tue, 24 Mar 2020 17:51:23 +0100 Subject: [PATCH 02/41] Merged MapsManaging branch --- app/src/main/java/ch/epfl/sdp/SavedMap.kt | 3 ++ .../main/java/ch/epfl/sdp/ui/MainActivity.kt | 5 +++ .../ui/maps/offline/MapsManagingFragment.kt | 31 ++++++++++++-- .../MapSelectionRecyclerViewAdapter.kt | 23 +++++++++++ .../sdp/ui/mapsManaging/SavedMapViewHolder.kt | 27 ++++++++++++ .../res/layout/fragment_maps_managing.xml | 5 ++- .../map_selection_recyclerview_item.xml | 41 +++++++++++++++++++ 7 files changed, 130 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/ch/epfl/sdp/SavedMap.kt create mode 100644 app/src/main/java/ch/epfl/sdp/ui/mapsManaging/MapSelectionRecyclerViewAdapter.kt create mode 100644 app/src/main/java/ch/epfl/sdp/ui/mapsManaging/SavedMapViewHolder.kt create mode 100644 app/src/main/res/layout/map_selection_recyclerview_item.xml diff --git a/app/src/main/java/ch/epfl/sdp/SavedMap.kt b/app/src/main/java/ch/epfl/sdp/SavedMap.kt new file mode 100644 index 000000000..080c6b938 --- /dev/null +++ b/app/src/main/java/ch/epfl/sdp/SavedMap.kt @@ -0,0 +1,3 @@ +package ch.epfl.sdp + +data class SavedMap(val name: String) \ No newline at end of file diff --git a/app/src/main/java/ch/epfl/sdp/ui/MainActivity.kt b/app/src/main/java/ch/epfl/sdp/ui/MainActivity.kt index 832aaea3b..3fa4a141d 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/MainActivity.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/MainActivity.kt @@ -25,6 +25,7 @@ import ch.epfl.sdp.R import ch.epfl.sdp.database.data.Role import ch.epfl.sdp.drone.Drone import ch.epfl.sdp.ui.maps.MapActivity +import ch.epfl.sdp.ui.maps.offline.OfflineManagerActivity import ch.epfl.sdp.ui.search_group.selection.SearchGroupSelectionActivity import ch.epfl.sdp.ui.search_group.selection.SearchGroupSelectionActivity.Companion.SEARH_GROUP_ID_SELECTION_RESULT_TAG import ch.epfl.sdp.ui.settings.SettingsActivity @@ -183,4 +184,8 @@ class MainActivity : AppCompatActivity() { val drawerLayout = findViewById(R.id.drawer_layout) drawerLayout.openDrawer(GravityCompat.START) } + + fun openMapForOfflineDownload (view: View?) { + startActivity(Intent(this, OfflineManagerActivity::class.java)) + } } diff --git a/app/src/main/java/ch/epfl/sdp/ui/maps/offline/MapsManagingFragment.kt b/app/src/main/java/ch/epfl/sdp/ui/maps/offline/MapsManagingFragment.kt index ceb53ad6e..77ac0a541 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/maps/offline/MapsManagingFragment.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/maps/offline/MapsManagingFragment.kt @@ -4,11 +4,13 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.TextView import androidx.fragment.app.Fragment -import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import ch.epfl.sdp.R +import ch.epfl.sdp.SavedMap +import ch.epfl.sdp.ui.mapsManaging.MapSelectionRecyclerViewAdapter +import kotlinx.android.synthetic.main.fragment_maps_managing.* class MapsManagingFragment : Fragment() { @@ -21,10 +23,33 @@ class MapsManagingFragment : Fragment() { ): View? { mapsManagingViewModel = ViewModelProvider(this).get(MapsManagingViewModel::class.java) val root = inflater.inflate(R.layout.fragment_maps_managing, container, false) - val textView: TextView = root.findViewById(R.id.text_slideshow) + /*val textView: TextView = root.findViewById(R.id.text_slideshow) mapsManagingViewModel.text.observe(viewLifecycleOwner, Observer { textView.text = getString(R.string.maps_managing) }) + textView.text = "Maps managing fragment\n(get offline maps here)" + })*/ return root } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + val mapNames: ArrayList = ArrayList() + mapNames.add(SavedMap("Matterhorn nord")) + mapNames.add(SavedMap("Matterhorn sud")) + mapNames.add(SavedMap("Diablerets")) + mapNames.add(SavedMap("Verbier sud")) + mapNames.add(SavedMap("Verbier ouest")) + mapNames.add(SavedMap("Glacier 3000")) + mapNames.add(SavedMap("Moleson")) + mapNames.add(SavedMap("Montblanc")) + super.onViewCreated(view, savedInstanceState) + // RecyclerView node initialized here + mapSelectionRecyclerview.apply { + // set a LinearLayoutManager to handle Android + // RecyclerView behavior + layoutManager = LinearLayoutManager(activity) + // set the custom adapter to the RecyclerView + adapter = MapSelectionRecyclerViewAdapter(mapNames) + } + } } diff --git a/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/MapSelectionRecyclerViewAdapter.kt b/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/MapSelectionRecyclerViewAdapter.kt new file mode 100644 index 000000000..049f8773e --- /dev/null +++ b/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/MapSelectionRecyclerViewAdapter.kt @@ -0,0 +1,23 @@ +package ch.epfl.sdp.ui.mapsManaging + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import ch.epfl.sdp.SavedMap + +class MapSelectionRecyclerViewAdapter(private val list: List) + : RecyclerView.Adapter() { + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SavedMapViewHolder { + val inflater = LayoutInflater.from(parent.context) + return SavedMapViewHolder(inflater, parent) + } + + override fun onBindViewHolder(holder: SavedMapViewHolder, position: Int) { + val savedMap: SavedMap = list[position] + holder.bind(savedMap) + } + + override fun getItemCount(): Int = list.size + +} \ No newline at end of file diff --git a/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/SavedMapViewHolder.kt b/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/SavedMapViewHolder.kt new file mode 100644 index 000000000..dd9c70466 --- /dev/null +++ b/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/SavedMapViewHolder.kt @@ -0,0 +1,27 @@ +package ch.epfl.sdp.ui.mapsManaging + +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import ch.epfl.sdp.R +import ch.epfl.sdp.SavedMap + +class SavedMapViewHolder(inflater: LayoutInflater, parent: ViewGroup) : + RecyclerView.ViewHolder(inflater.inflate(R.layout.map_selection_recyclerview_item, parent, false)) { + private var mTitleView: TextView? + private var mOtherView: TextView? + + + + init { + mTitleView = itemView.findViewById(R.id.savedMapName) + mOtherView = itemView.findViewById(R.id.savedMapOtherProperty) + } + + fun bind(savedMap: SavedMap) { + mTitleView?.text = savedMap.name + mOtherView?.text = "Used space: 213.34 Mb" + } + +} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_maps_managing.xml b/app/src/main/res/layout/fragment_maps_managing.xml index b193d9275..b86fc8c35 100644 --- a/app/src/main/res/layout/fragment_maps_managing.xml +++ b/app/src/main/res/layout/fragment_maps_managing.xml @@ -6,8 +6,8 @@ android:layout_height="match_parent" tools:context=".ui.maps.offline.MapsManagingFragment"> - + + + + + + + + + + + + + + + + From 110812e3963b36120b8a7d040c8a6300be61701e Mon Sep 17 00:00:00 2001 From: AlexisTabin Date: Wed, 20 May 2020 17:03:16 +0200 Subject: [PATCH 03/41] Maps Managing Fragment now shows Downloaded Offline Regions --- app/src/main/java/ch/epfl/sdp/SavedMap.kt | 3 -- .../ui/maps/offline/MapsManagingFragment.kt | 44 +++++++++++-------- .../ui/maps/offline/OfflineManagerActivity.kt | 5 --- .../MapSelectionRecyclerViewAdapter.kt | 18 ++++---- ...pViewHolder.kt => OfflineMapViewHolder.kt} | 16 ++++--- 5 files changed, 44 insertions(+), 42 deletions(-) delete mode 100644 app/src/main/java/ch/epfl/sdp/SavedMap.kt rename app/src/main/java/ch/epfl/sdp/ui/mapsManaging/{SavedMapViewHolder.kt => OfflineMapViewHolder.kt} (54%) diff --git a/app/src/main/java/ch/epfl/sdp/SavedMap.kt b/app/src/main/java/ch/epfl/sdp/SavedMap.kt deleted file mode 100644 index 080c6b938..000000000 --- a/app/src/main/java/ch/epfl/sdp/SavedMap.kt +++ /dev/null @@ -1,3 +0,0 @@ -package ch.epfl.sdp - -data class SavedMap(val name: String) \ No newline at end of file diff --git a/app/src/main/java/ch/epfl/sdp/ui/maps/offline/MapsManagingFragment.kt b/app/src/main/java/ch/epfl/sdp/ui/maps/offline/MapsManagingFragment.kt index 77ac0a541..9f1622e77 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/maps/offline/MapsManagingFragment.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/maps/offline/MapsManagingFragment.kt @@ -7,21 +7,25 @@ import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager +import ch.epfl.sdp.MainApplication import ch.epfl.sdp.R -import ch.epfl.sdp.SavedMap +import ch.epfl.sdp.map.offline.OfflineRegionUtils import ch.epfl.sdp.ui.mapsManaging.MapSelectionRecyclerViewAdapter +import com.mapbox.mapboxsdk.offline.OfflineManager +import com.mapbox.mapboxsdk.offline.OfflineRegion import kotlinx.android.synthetic.main.fragment_maps_managing.* class MapsManagingFragment : Fragment() { private lateinit var mapsManagingViewModel: MapsManagingViewModel - + private lateinit var offlineManager: OfflineManager override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { mapsManagingViewModel = ViewModelProvider(this).get(MapsManagingViewModel::class.java) + offlineManager = OfflineManager.getInstance(MainApplication.applicationContext()) val root = inflater.inflate(R.layout.fragment_maps_managing, container, false) /*val textView: TextView = root.findViewById(R.id.text_slideshow) mapsManagingViewModel.text.observe(viewLifecycleOwner, Observer { @@ -33,23 +37,25 @@ class MapsManagingFragment : Fragment() { } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - val mapNames: ArrayList = ArrayList() - mapNames.add(SavedMap("Matterhorn nord")) - mapNames.add(SavedMap("Matterhorn sud")) - mapNames.add(SavedMap("Diablerets")) - mapNames.add(SavedMap("Verbier sud")) - mapNames.add(SavedMap("Verbier ouest")) - mapNames.add(SavedMap("Glacier 3000")) - mapNames.add(SavedMap("Moleson")) - mapNames.add(SavedMap("Montblanc")) + // Build a region list when the user clicks the list button + // Query the DB asynchronously + offlineManager.listOfflineRegions(object : OfflineManager.ListOfflineRegionsCallback { + override fun onList(offlineRegions: Array) { // Check result. If no regions have been + // RecyclerView node initialized here + mapSelectionRecyclerview.apply { + // set a LinearLayoutManager to handle Android + // RecyclerView behavior + layoutManager = LinearLayoutManager(activity) + // set the custom adapter to the RecyclerView + adapter = MapSelectionRecyclerViewAdapter(offlineRegions) + } + } + + override fun onError(error: String) { + OfflineRegionUtils.showErrorAndToast("Error : $error") + } + }) + super.onViewCreated(view, savedInstanceState) - // RecyclerView node initialized here - mapSelectionRecyclerview.apply { - // set a LinearLayoutManager to handle Android - // RecyclerView behavior - layoutManager = LinearLayoutManager(activity) - // set the custom adapter to the RecyclerView - adapter = MapSelectionRecyclerViewAdapter(mapNames) - } } } diff --git a/app/src/main/java/ch/epfl/sdp/ui/maps/offline/OfflineManagerActivity.kt b/app/src/main/java/ch/epfl/sdp/ui/maps/offline/OfflineManagerActivity.kt index e8e299ad0..fd15085cd 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/maps/offline/OfflineManagerActivity.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/maps/offline/OfflineManagerActivity.kt @@ -5,7 +5,6 @@ import android.view.View import android.widget.Button import android.widget.ProgressBar import android.widget.Toast -import ch.epfl.sdp.MainApplication import ch.epfl.sdp.R import ch.epfl.sdp.map.MapUtils import ch.epfl.sdp.map.offline.DownloadProgressBarUtils.downloadingInProgress @@ -38,8 +37,6 @@ class OfflineManagerActivity : MapViewBaseActivity(), OnMapReadyCallback { private lateinit var offlineManager: OfflineManager private lateinit var progressBar: ProgressBar - private var regionSelected = 0 - companion object { // JSON encoding/decoding const val JSON_CHARSET = "UTF-8" @@ -153,8 +150,6 @@ class OfflineManagerActivity : MapViewBaseActivity(), OnMapReadyCallback { } fun downloadedRegionList(v: View) { // Build a region list when the user clicks the list button - // Reset the region selected int to 0 - regionSelected = 0 // Query the DB asynchronously offlineManager.listOfflineRegions(object : ListOfflineRegionsCallback { override fun onList(offlineRegions: Array) { // Check result. If no regions have been diff --git a/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/MapSelectionRecyclerViewAdapter.kt b/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/MapSelectionRecyclerViewAdapter.kt index 049f8773e..9c106e0e3 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/MapSelectionRecyclerViewAdapter.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/MapSelectionRecyclerViewAdapter.kt @@ -3,21 +3,21 @@ package ch.epfl.sdp.ui.mapsManaging import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView -import ch.epfl.sdp.SavedMap +import com.mapbox.mapboxsdk.offline.OfflineRegion -class MapSelectionRecyclerViewAdapter(private val list: List) - : RecyclerView.Adapter() { +class MapSelectionRecyclerViewAdapter(private val regions: Array) + : RecyclerView.Adapter() { - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SavedMapViewHolder { + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): OfflineMapViewHolder { val inflater = LayoutInflater.from(parent.context) - return SavedMapViewHolder(inflater, parent) + return OfflineMapViewHolder(inflater, parent) } - override fun onBindViewHolder(holder: SavedMapViewHolder, position: Int) { - val savedMap: SavedMap = list[position] - holder.bind(savedMap) + override fun onBindViewHolder(holder: OfflineMapViewHolder, position: Int) { + val offlineRegion: OfflineRegion = regions[position] + holder.bind(offlineRegion) } - override fun getItemCount(): Int = list.size + override fun getItemCount(): Int = regions.size } \ No newline at end of file diff --git a/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/SavedMapViewHolder.kt b/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/OfflineMapViewHolder.kt similarity index 54% rename from app/src/main/java/ch/epfl/sdp/ui/mapsManaging/SavedMapViewHolder.kt rename to app/src/main/java/ch/epfl/sdp/ui/mapsManaging/OfflineMapViewHolder.kt index dd9c70466..181a93040 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/SavedMapViewHolder.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/OfflineMapViewHolder.kt @@ -4,23 +4,27 @@ import android.view.LayoutInflater import android.view.ViewGroup import android.widget.TextView import androidx.recyclerview.widget.RecyclerView +import ch.epfl.sdp.MainApplication import ch.epfl.sdp.R -import ch.epfl.sdp.SavedMap +import ch.epfl.sdp.map.offline.OfflineRegionUtils +import com.mapbox.mapboxsdk.offline.OfflineRegion -class SavedMapViewHolder(inflater: LayoutInflater, parent: ViewGroup) : +class OfflineMapViewHolder(inflater: LayoutInflater, parent: ViewGroup) : RecyclerView.ViewHolder(inflater.inflate(R.layout.map_selection_recyclerview_item, parent, false)) { private var mTitleView: TextView? private var mOtherView: TextView? - - init { mTitleView = itemView.findViewById(R.id.savedMapName) mOtherView = itemView.findViewById(R.id.savedMapOtherProperty) } - fun bind(savedMap: SavedMap) { - mTitleView?.text = savedMap.name + fun bind(region: OfflineRegion) { + mTitleView?.text = try { + OfflineRegionUtils.getRegionName(region) + } catch (exception: java.lang.Exception) { + String.format(MainApplication.applicationContext().getString(R.string.region_name_error), region.id) + } mOtherView?.text = "Used space: 213.34 Mb" } From 09909d9bb42c60ecb2610eb2ddd7533ca3cfe347 Mon Sep 17 00:00:00 2001 From: AlexisTabin Date: Wed, 20 May 2020 17:26:32 +0200 Subject: [PATCH 04/41] Added number of Tiles for each Region --- .../ui/maps/offline/MapsManagingFragment.kt | 12 +------ .../ui/mapsManaging/OfflineMapViewHolder.kt | 33 +++++++++++++------ .../map_selection_recyclerview_item.xml | 4 +-- app/src/main/res/values/strings.xml | 1 + 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/ch/epfl/sdp/ui/maps/offline/MapsManagingFragment.kt b/app/src/main/java/ch/epfl/sdp/ui/maps/offline/MapsManagingFragment.kt index 9f1622e77..684a9cd30 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/maps/offline/MapsManagingFragment.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/maps/offline/MapsManagingFragment.kt @@ -26,19 +26,10 @@ class MapsManagingFragment : Fragment() { ): View? { mapsManagingViewModel = ViewModelProvider(this).get(MapsManagingViewModel::class.java) offlineManager = OfflineManager.getInstance(MainApplication.applicationContext()) - val root = inflater.inflate(R.layout.fragment_maps_managing, container, false) - /*val textView: TextView = root.findViewById(R.id.text_slideshow) - mapsManagingViewModel.text.observe(viewLifecycleOwner, Observer { - textView.text = getString(R.string.maps_managing) - }) - textView.text = "Maps managing fragment\n(get offline maps here)" - })*/ - return root + return inflater.inflate(R.layout.fragment_maps_managing, container, false) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - // Build a region list when the user clicks the list button - // Query the DB asynchronously offlineManager.listOfflineRegions(object : OfflineManager.ListOfflineRegionsCallback { override fun onList(offlineRegions: Array) { // Check result. If no regions have been // RecyclerView node initialized here @@ -55,7 +46,6 @@ class MapsManagingFragment : Fragment() { OfflineRegionUtils.showErrorAndToast("Error : $error") } }) - super.onViewCreated(view, savedInstanceState) } } diff --git a/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/OfflineMapViewHolder.kt b/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/OfflineMapViewHolder.kt index 181a93040..0bb017243 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/OfflineMapViewHolder.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/OfflineMapViewHolder.kt @@ -8,24 +8,37 @@ import ch.epfl.sdp.MainApplication import ch.epfl.sdp.R import ch.epfl.sdp.map.offline.OfflineRegionUtils import com.mapbox.mapboxsdk.offline.OfflineRegion +import com.mapbox.mapboxsdk.offline.OfflineRegionStatus class OfflineMapViewHolder(inflater: LayoutInflater, parent: ViewGroup) : RecyclerView.ViewHolder(inflater.inflate(R.layout.map_selection_recyclerview_item, parent, false)) { - private var mTitleView: TextView? - private var mOtherView: TextView? - - init { - mTitleView = itemView.findViewById(R.id.savedMapName) - mOtherView = itemView.findViewById(R.id.savedMapOtherProperty) - } + private var nameView: TextView? = itemView.findViewById(R.id.offlineRegionName) + private var propertyView: TextView? = itemView.findViewById(R.id.offlineRegionProperty) fun bind(region: OfflineRegion) { - mTitleView?.text = try { + nameView?.text = try { OfflineRegionUtils.getRegionName(region) } catch (exception: java.lang.Exception) { String.format(MainApplication.applicationContext().getString(R.string.region_name_error), region.id) } - mOtherView?.text = "Used space: 213.34 Mb" - } + region.getStatus(object : OfflineRegion.OfflineRegionStatusCallback { + /** + * Receives the status + * + * @param status the offline region status + */ + override fun onStatus(status: OfflineRegionStatus?) { + propertyView?.text = MainApplication.applicationContext().getString(R.string.offline_region_tiles, status?.completedResourceCount) + } + /** + * Receives the error message + * + * @param error the error message + */ + override fun onError(error: String?) { + OfflineRegionUtils.showErrorAndToast("Error : $error") + } + }) + } } \ No newline at end of file diff --git a/app/src/main/res/layout/map_selection_recyclerview_item.xml b/app/src/main/res/layout/map_selection_recyclerview_item.xml index 588afc08b..4efb065f2 100644 --- a/app/src/main/res/layout/map_selection_recyclerview_item.xml +++ b/app/src/main/res/layout/map_selection_recyclerview_item.xml @@ -22,14 +22,14 @@ android:orientation="vertical"> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index eb5f76e24..272a67824 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -66,6 +66,7 @@ No regions yet Name cannot be empty Unknown Region name + Number of tiles : %1$d Maps managing fragment\n(get offline maps here) Download Region Dialog Fragment List Offline Region Dialog Fragment From ae55fdd628a3aa20f503a806b775a545d323a302 Mon Sep 17 00:00:00 2001 From: AlexisTabin Date: Wed, 20 May 2020 19:11:51 +0200 Subject: [PATCH 05/41] add OfflineMapsManagingTest --- .../java/ch/epfl/sdp/MainActivityTest.kt | 6 -- .../sdp/ui/offline/OfflineMapsManagingTest.kt | 83 +++++++++++++++++++ .../MapSelectionRecyclerViewAdapter.kt | 7 +- .../res/layout/fragment_maps_managing.xml | 12 +++ 4 files changed, 97 insertions(+), 11 deletions(-) create mode 100644 app/src/androidTest/java/ch/epfl/sdp/ui/offline/OfflineMapsManagingTest.kt diff --git a/app/src/androidTest/java/ch/epfl/sdp/MainActivityTest.kt b/app/src/androidTest/java/ch/epfl/sdp/MainActivityTest.kt index 7eaa68902..6b7c37c10 100644 --- a/app/src/androidTest/java/ch/epfl/sdp/MainActivityTest.kt +++ b/app/src/androidTest/java/ch/epfl/sdp/MainActivityTest.kt @@ -77,12 +77,6 @@ class MainActivityTest { .perform(NavigationViewActions.navigateTo(R.id.nav_home)) } - @Test - fun canNavigateToMapsManaging() { - openDrawer() - onView(withId(R.id.nav_view)) - .perform(NavigationViewActions.navigateTo(R.id.nav_maps_managing)) - } @Test fun canDisplayAMapAndReloadLocation() { val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext()) diff --git a/app/src/androidTest/java/ch/epfl/sdp/ui/offline/OfflineMapsManagingTest.kt b/app/src/androidTest/java/ch/epfl/sdp/ui/offline/OfflineMapsManagingTest.kt new file mode 100644 index 000000000..33ce1a33b --- /dev/null +++ b/app/src/androidTest/java/ch/epfl/sdp/ui/offline/OfflineMapsManagingTest.kt @@ -0,0 +1,83 @@ +package ch.epfl.sdp.ui.offline + +import android.Manifest.permission.ACCESS_FINE_LOCATION +import android.content.Context +import android.view.Gravity +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.contrib.DrawerActions +import androidx.test.espresso.contrib.DrawerMatchers.isClosed +import androidx.test.espresso.contrib.NavigationViewActions +import androidx.test.espresso.intent.Intents +import androidx.test.espresso.intent.matcher.IntentMatchers +import androidx.test.espresso.intent.rule.IntentsTestRule +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation +import androidx.test.rule.GrantPermissionRule +import androidx.test.rule.GrantPermissionRule.grant +import androidx.test.uiautomator.By +import androidx.test.uiautomator.UiDevice +import androidx.test.uiautomator.Until +import ch.epfl.sdp.MainApplication +import ch.epfl.sdp.R +import ch.epfl.sdp.ui.MainActivity +import ch.epfl.sdp.ui.maps.offline.OfflineManagerActivity +import org.junit.Before +import org.junit.BeforeClass +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +class OfflineMapsManagingTest { + + private lateinit var mUiDevice: UiDevice + private val FAKE_MAP_NAME_1 = "RandomName" + private val POSITIVE_BUTTON_ID: Int = android.R.id.button1 + private val NEGATIVE_BUTTON_ID: Int = android.R.id.button2 + private val MAP_LOADING_TIMEOUT = 1000L + + @Rule + @JvmField + val grantPermissionRule: GrantPermissionRule = grant(ACCESS_FINE_LOCATION, ACCESS_FINE_LOCATION) + + @get:Rule + val mActivityRule = IntentsTestRule(MainActivity::class.java) + + @Before + @Throws(Exception::class) + fun before() { + mUiDevice = UiDevice.getInstance(getInstrumentation()) + } + + private fun getContext(): Context { + return getInstrumentation().targetContext + } + + private fun openDrawer() { + onView(withId(R.id.drawer_layout)) + .check(matches(isClosed(Gravity.LEFT))) // Check that drawer is closed to begin with + .perform(DrawerActions.open()) + } + + @Test + fun canNavigateToMapsManaging() { + openDrawer() + onView(withId(R.id.nav_view)) + .perform(NavigationViewActions.navigateTo(R.id.nav_maps_managing)) + } + + @Test + fun canLaunchOfflineManagerActivity() { + openDrawer() + onView(withId(R.id.nav_view)) + .perform(NavigationViewActions.navigateTo(R.id.nav_maps_managing)) + onView(withId(R.id.store_button)) + .perform(click()) + + Intents.intended(IntentMatchers.hasComponent(OfflineManagerActivity::class.java.name)) + } +} \ No newline at end of file diff --git a/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/MapSelectionRecyclerViewAdapter.kt b/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/MapSelectionRecyclerViewAdapter.kt index 9c106e0e3..229c873df 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/MapSelectionRecyclerViewAdapter.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/MapSelectionRecyclerViewAdapter.kt @@ -9,15 +9,12 @@ class MapSelectionRecyclerViewAdapter(private val regions: Array) : RecyclerView.Adapter() { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): OfflineMapViewHolder { - val inflater = LayoutInflater.from(parent.context) - return OfflineMapViewHolder(inflater, parent) + return OfflineMapViewHolder(LayoutInflater.from(parent.context), parent) } override fun onBindViewHolder(holder: OfflineMapViewHolder, position: Int) { - val offlineRegion: OfflineRegion = regions[position] - holder.bind(offlineRegion) + holder.bind(regions[position]) } override fun getItemCount(): Int = regions.size - } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_maps_managing.xml b/app/src/main/res/layout/fragment_maps_managing.xml index b86fc8c35..71e1669cf 100644 --- a/app/src/main/res/layout/fragment_maps_managing.xml +++ b/app/src/main/res/layout/fragment_maps_managing.xml @@ -21,4 +21,16 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> + + \ No newline at end of file From dc23cafe13dde1c8b5eebf709a9bd59ee2500ca8 Mon Sep 17 00:00:00 2001 From: Bastien Wermeille <5320541+Ph0tonic@users.noreply.github.com> Date: Sun, 31 May 2020 10:48:29 +0200 Subject: [PATCH 06/41] Reorganise files --- .../offline}/MapSelectionRecyclerViewAdapter.kt | 2 +- .../java/ch/epfl/sdp/ui/maps/offline/MapsManagingFragment.kt | 1 - .../ui/{mapsManaging => maps/offline}/OfflineMapViewHolder.kt | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) rename app/src/main/java/ch/epfl/sdp/ui/{mapsManaging => maps/offline}/MapSelectionRecyclerViewAdapter.kt (94%) rename app/src/main/java/ch/epfl/sdp/ui/{mapsManaging => maps/offline}/OfflineMapViewHolder.kt (97%) diff --git a/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/MapSelectionRecyclerViewAdapter.kt b/app/src/main/java/ch/epfl/sdp/ui/maps/offline/MapSelectionRecyclerViewAdapter.kt similarity index 94% rename from app/src/main/java/ch/epfl/sdp/ui/mapsManaging/MapSelectionRecyclerViewAdapter.kt rename to app/src/main/java/ch/epfl/sdp/ui/maps/offline/MapSelectionRecyclerViewAdapter.kt index 229c873df..d9cea0b4c 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/MapSelectionRecyclerViewAdapter.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/maps/offline/MapSelectionRecyclerViewAdapter.kt @@ -1,4 +1,4 @@ -package ch.epfl.sdp.ui.mapsManaging +package ch.epfl.sdp.ui.maps.offline import android.view.LayoutInflater import android.view.ViewGroup diff --git a/app/src/main/java/ch/epfl/sdp/ui/maps/offline/MapsManagingFragment.kt b/app/src/main/java/ch/epfl/sdp/ui/maps/offline/MapsManagingFragment.kt index 684a9cd30..f1b129d26 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/maps/offline/MapsManagingFragment.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/maps/offline/MapsManagingFragment.kt @@ -10,7 +10,6 @@ import androidx.recyclerview.widget.LinearLayoutManager import ch.epfl.sdp.MainApplication import ch.epfl.sdp.R import ch.epfl.sdp.map.offline.OfflineRegionUtils -import ch.epfl.sdp.ui.mapsManaging.MapSelectionRecyclerViewAdapter import com.mapbox.mapboxsdk.offline.OfflineManager import com.mapbox.mapboxsdk.offline.OfflineRegion import kotlinx.android.synthetic.main.fragment_maps_managing.* diff --git a/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/OfflineMapViewHolder.kt b/app/src/main/java/ch/epfl/sdp/ui/maps/offline/OfflineMapViewHolder.kt similarity index 97% rename from app/src/main/java/ch/epfl/sdp/ui/mapsManaging/OfflineMapViewHolder.kt rename to app/src/main/java/ch/epfl/sdp/ui/maps/offline/OfflineMapViewHolder.kt index 0bb017243..073dbea2e 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/mapsManaging/OfflineMapViewHolder.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/maps/offline/OfflineMapViewHolder.kt @@ -1,4 +1,4 @@ -package ch.epfl.sdp.ui.mapsManaging +package ch.epfl.sdp.ui.maps.offline import android.view.LayoutInflater import android.view.ViewGroup From add9605f38d578667f8270b6f6d347581ff945ea Mon Sep 17 00:00:00 2001 From: Dorian Date: Thu, 4 Jun 2020 10:11:13 +0200 Subject: [PATCH 07/41] Improve --- .../main/java/ch/epfl/sdp/ui/MainActivity.kt | 6 +++++ .../ListOfflineRegionDialogFragment.kt | 16 +++----------- .../ui/maps/offline/OfflineManagerActivity.kt | 22 +++++++++---------- .../res/layout/activity_offline_manager.xml | 8 +++---- .../map_selection_recyclerview_item.xml | 3 ++- app/src/main/res/values/strings.xml | 2 ++ 6 files changed, 27 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/ch/epfl/sdp/ui/MainActivity.kt b/app/src/main/java/ch/epfl/sdp/ui/MainActivity.kt index 6f6603036..f656de855 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/MainActivity.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/MainActivity.kt @@ -149,4 +149,10 @@ class MainActivity : AppCompatActivity() { fun openMapForOfflineDownload (view: View?) { startActivity(Intent(this, OfflineManagerActivity::class.java)) } + + fun openExistingOfflineMap (view: View?) { + val intent = Intent(this, OfflineManagerActivity::class.java) + intent.putExtra(getString(R.string.intent_key_show_delete_button), true) + startActivity(intent) + } } diff --git a/app/src/main/java/ch/epfl/sdp/ui/maps/offline/ListOfflineRegionDialogFragment.kt b/app/src/main/java/ch/epfl/sdp/ui/maps/offline/ListOfflineRegionDialogFragment.kt index cee369ac4..a5073c89c 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/maps/offline/ListOfflineRegionDialogFragment.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/maps/offline/ListOfflineRegionDialogFragment.kt @@ -14,25 +14,15 @@ import com.mapbox.mapboxsdk.maps.MapView import com.mapbox.mapboxsdk.maps.MapboxMap import com.mapbox.mapboxsdk.offline.OfflineRegion -class ListOfflineRegionDialogFragment(private val items: Array, - private val offlineRegions: Array, - private val mapboxMap: MapboxMap, +class ListOfflineRegionDialogFragment(private val offlineRegions: Array, private val progressBar: ProgressBar, private val mapView: MapView) : DialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { return activity.let { var regionSelected = 0 AlertDialog.Builder(it) - .setTitle(getString(R.string.navigate_title)).setSingleChoiceItems(items, 0) { _, which -> regionSelected = which } - .setPositiveButton(getString(R.string.navigate_positive_button)) { _, _ -> - Toast.makeText(it, items[regionSelected], Toast.LENGTH_LONG).show() - // Create new camera position - val definition = offlineRegions[regionSelected].definition - mapboxMap.cameraPosition = MapUtils.getCameraWithParameters( - definition.bounds.center, - definition.minZoom) - } - .setNeutralButton(getString(R.string.navigate_neutral_button_title)) { _, _ -> + .setTitle(getString(R.string.navigate_title)) + .setPositiveButton(getString(R.string.navigate_neutral_button_title)) { _, _ -> // Make progressBar indeterminate and // set it to visible to signal that // the deletion process has begun diff --git a/app/src/main/java/ch/epfl/sdp/ui/maps/offline/OfflineManagerActivity.kt b/app/src/main/java/ch/epfl/sdp/ui/maps/offline/OfflineManagerActivity.kt index d29690845..996dc43d3 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/maps/offline/OfflineManagerActivity.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/maps/offline/OfflineManagerActivity.kt @@ -47,6 +47,14 @@ class OfflineManagerActivity : MapViewBaseActivity(), OnMapReadyCallback { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) super.initMapView(savedInstanceState, R.layout.activity_offline_manager, R.id.mapView) + + val showDelete = intent.getBooleanExtra(getString(R.string.intent_key_show_delete_button), false) + if (!showDelete){ + findViewById