I'm trying to learn MVVM, and I faced some issue which I don't know how to resolve. I wanted to make a repository which will get user coordinates in background thread. The thing is in order to make it work, I have to pass context for it, but I don't know how to pass context for repository. I can't just pass it that easily like in some activity class.
Repository
public class LocationRepository {
private void test() {
FusedLocationProviderClient client = LocationServices.getFusedLocationProviderClient(CONTEXT);
{
if (ContextCompat.checkSelfPermission(CONTEXT, Manifest.permission.INTERNET) == PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(CONTEXT, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(CONTEXT, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
client.getLastLocation().addOnSuccessListener(CONTEXT, new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if (location != null){
//TODO
}
}
});
}
else{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{
Manifest.permission.INTERNET, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION
}, 1);
}
}
}
}
}