Skip to content

Instantly share code, notes, and snippets.

@talosdev
Last active January 12, 2019 10:53
Show Gist options
  • Select an option

  • Save talosdev/f56160250fb068f72e836e34976a9c31 to your computer and use it in GitHub Desktop.

Select an option

Save talosdev/f56160250fb068f72e836e34976a9c31 to your computer and use it in GitHub Desktop.
public class LocationActivity extends AppCompatActivity
implements LocationContract.View {
@BindView(R.id.latitudeTextView)
TextView latitudeTextView;
@BindView(R.id.longitudeTextView)
TextView longitudeTextView;
@BindView(R.id.softDenyTextView)
TextView softDeniedWarningTextView;
@BindView(R.id.hardDenyTextView)
TextView hardDeniedWarningTextView;
@BindViews({R.id.softDenyTextView, R.id.hardDenyTextView})
List<TextView> deniedTextViews;
private static final ButterKnife.Action<View> VISIBLE =
(v, index) -> v.setVisibility(View.VISIBLE);
private static final ButterKnife.Action<View> GONE =
(v, index) -> v.setVisibility(View.GONE);
@Inject
LocationContract.Presenter presenter;
@Inject
PermissionsRequestResultDispatcher permissionsRequestResultDispatcher;
@Inject
@Named("locationReqCode")
Integer locationRequestCode;
public static Intent newIntent(Context context) {
return new Intent(context, LocationActivity.class);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
AndroidInjection.inject(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.location_activity);
ButterKnife.bind(this);
}
@Override
protected void onStart() {
super.onStart();
presenter.loadData();
}
@Override
public void showLatitude(String latitude) {
latitudeTextView.setText(latitude);
}
@Override
public void showLongitude(String longitude) {
longitudeTextView.setText(longitude);
}
@Override
public void showNoLocationAvailable() {
Toast.makeText(LocationActivity.this, R.string.error_accessing_location,
Toast.LENGTH_SHORT).show();
}
@Override
public void showGenericError() {
Toast.makeText(LocationActivity.this, R.string.error_generic,
Toast.LENGTH_SHORT).show();
}
@Override
public void showSoftDenied() {
ButterKnife.apply(softDeniedWarningTextView, VISIBLE);
ButterKnife.apply(hardDeniedWarningTextView, GONE);
}
@Override
public void showHardDenied() {
ButterKnife.apply(hardDeniedWarningTextView, VISIBLE);
ButterKnife.apply(softDeniedWarningTextView, GONE);
}
@Override
public void hidePermissionDeniedWarning() {
ButterKnife.apply(deniedTextViews, GONE);
}
@OnClick(R.id.softDenyTextView)
void softDenyTextViewClicked(View view) {
presenter.loadData();
}
@OnClick(R.id.hardDenyTextView)
void hardDenyTextViewClicked(View view) {
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
startActivity(intent);
}
@Override
protected void onDestroy() {
super.onDestroy();
presenter.cleanup();
}
@Override
@SuppressWarnings({"MissingPermission"})
public void onRequestPermissionsResult(int requestCode,
@NonNull String[] permissions,
@NonNull int[] grantResults) {
if (requestCode == locationRequestCode) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
permissionsRequestResultDispatcher.dispatchResult(true);
} else {
permissionsRequestResultDispatcher.dispatchResult(false);
}
} else {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment