Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #159 from scolsen/basemap-selector
Offline Imagery: Add basemap selector UI
- Loading branch information
Showing
12 changed files
with
194 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
gnd/src/main/java/com/google/android/gnd/ui/basemapselector/BasemapSelectorFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.google.android.gnd.ui.basemapselector; | ||
|
||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.core.view.ViewCompat; | ||
import androidx.core.view.WindowInsetsCompat; | ||
|
||
import com.google.android.gnd.MainViewModel; | ||
import com.google.android.gnd.R; | ||
import com.google.android.gnd.databinding.BasemapSelectorFragBinding; | ||
import com.google.android.gnd.inject.ActivityScoped; | ||
import com.google.android.gnd.ui.common.AbstractFragment; | ||
import com.google.android.gnd.ui.map.MapProvider; | ||
import com.google.android.gnd.ui.map.MapProvider.MapAdapter; | ||
|
||
import javax.inject.Inject; | ||
|
||
import io.reactivex.Single; | ||
|
||
/** | ||
* Allows the user to select specific areas on a map for offline display. Users can toggle sections of | ||
* the map to add or remove imagery. Upon selection, basemap tiles are queued for download. When | ||
* deselected, they are removed from the device. | ||
*/ | ||
@ActivityScoped | ||
public class BasemapSelectorFragment extends AbstractFragment { | ||
|
||
private static final String TAG = BasemapSelectorFragment.class.getName(); | ||
private static final String MAP_FRAGMENT_KEY = MapProvider.class.getName() + "#fragment"; | ||
private BasemapSelectorViewModel viewModel; | ||
private MainViewModel mainViewModel; | ||
|
||
@Inject MapProvider mapProvider; | ||
|
||
@Override | ||
public void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
viewModel = getViewModel(BasemapSelectorViewModel.class); | ||
mainViewModel = getViewModel(MainViewModel.class); | ||
Single<MapAdapter> mapAdapter = mapProvider.getMapAdapter(); | ||
} | ||
|
||
@Override | ||
public View onCreateView( | ||
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
BasemapSelectorFragBinding binding = | ||
BasemapSelectorFragBinding.inflate(inflater, container, false); | ||
binding.setViewModel(viewModel); | ||
return binding.getRoot(); | ||
} | ||
|
||
@Override | ||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { | ||
super.onViewCreated(view, savedInstanceState); | ||
if (savedInstanceState == null) { | ||
replaceFragment(R.id.map, mapProvider.getFragment()); | ||
} else { | ||
mapProvider.restore(restoreChildFragment(savedInstanceState, MAP_FRAGMENT_KEY)); | ||
} | ||
} | ||
|
||
@Override | ||
public void onActivityCreated(@Nullable Bundle savedInstanceState) { | ||
super.onActivityCreated(savedInstanceState); | ||
mainViewModel.getWindowInsets().observe(this, this::onApplyWindowInsets); | ||
} | ||
|
||
private void onApplyWindowInsets(WindowInsetsCompat windowInsets) { | ||
ViewCompat.onApplyWindowInsets(mapProvider.getFragment().getView(), windowInsets); | ||
// TODO: Once we add control UI elements, translate them based on the inset to avoid collision | ||
// with the android navbar. | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
gnd/src/main/java/com/google/android/gnd/ui/basemapselector/BasemapSelectorModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.google.android.gnd.ui.basemapselector; | ||
|
||
import androidx.fragment.app.Fragment; | ||
|
||
import com.google.android.gnd.inject.FragmentScoped; | ||
|
||
import dagger.Binds; | ||
import dagger.Module; | ||
|
||
@Module | ||
public abstract class BasemapSelectorModule { | ||
|
||
@Binds | ||
@FragmentScoped | ||
abstract Fragment fragment(BasemapSelectorFragment fragment); | ||
} |
19 changes: 19 additions & 0 deletions
19
gnd/src/main/java/com/google/android/gnd/ui/basemapselector/BasemapSelectorViewModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.google.android.gnd.ui.basemapselector; | ||
|
||
import androidx.lifecycle.ViewModel; | ||
|
||
import javax.inject.Inject; | ||
|
||
/** | ||
* This view model is responsible for managing state for the {@link BasemapSelectorFragment}. | ||
* Together, they constitute a basemap selector that users can interact with to select portions of a | ||
* basemap for offline viewing. Among other things, this view model is responsible for receiving | ||
* requests to download basemap files and for scheduling those requests with an {@link | ||
* com.google.android.gnd.workers.FileDownloadWorker}. | ||
*/ | ||
public class BasemapSelectorViewModel extends ViewModel { | ||
@Inject | ||
BasemapSelectorViewModel() {} | ||
|
||
// TODO: Implement view model. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
||
<data> | ||
<variable | ||
name="viewModel" | ||
type="com.google.android.gnd.ui.basemapselector.BasemapSelectorViewModel" /> | ||
</data> | ||
|
||
<FrameLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<RelativeLayout | ||
android:id="@+id/map_layout" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_gravity="top" | ||
android:gravity="center" | ||
app:layout_behavior="com.google.android.gnd.ui.home.mapcontainer.MapLayoutBehavior"> | ||
|
||
<FrameLayout | ||
android:id="@+id/map" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
|
||
<!--TODO: Add controls for returning Home and downloading selected tiles.--> | ||
</RelativeLayout> | ||
</FrameLayout> | ||
</layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters