Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored code for runtime permissions #598

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ protected void onCreate(Bundle savedInstanceState) {

fragmentManager.beginTransaction().replace(R.id.inc, fragment).commit();

// Get runtime permissions for Android M
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you remove these? I didnt get the point for this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed these permissions because they will trigger the permissions to be asked if the user is just going to log-in or sign-up. I wanted the permissions to be only used at activities/app sections where it is only necessary.

@thedevelopersanjeev 's implementation could be better but it's already asking for permissions at first time use for user and it doesn't take into account if the user declines all permissions.

getRuntimePermissions();

mDrawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,
mDrawer,
Expand Down Expand Up @@ -302,31 +299,6 @@ private Fragment getFragmentByNavMenuItemId(int id) {

return fragment;
}

private void getRuntimePermissions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.CAMERA,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.BLUETOOTH,
Manifest.permission.BLUETOOTH_ADMIN,
Manifest.permission.READ_CONTACTS,
Manifest.permission.WRITE_CONTACTS,
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.WAKE_LOCK,
Manifest.permission.INTERNET,
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.VIBRATE,
}, 0);
}
}
}

public static Intent getStartIntent(Context context) {
Intent intent = new Intent(context, MainActivity.class);
return intent;
Expand Down Expand Up @@ -506,4 +478,6 @@ protected void onSaveInstanceState(Bundle outState) {
public NavigationView getNavigationView() {
return mNavigationView;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ protected void onCreate(Bundle savedInstanceState) {
mHandler = new Handler(Looper.getMainLooper());
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

// Get runtime permissions for Android M
getRunTimePermissions();

signup.setOnClickListener(this);
login.setOnClickListener(this);
ok_login.setOnClickListener(this);
Expand Down Expand Up @@ -244,6 +241,7 @@ public void onClick(View view) {
}
}


@Override
public void rememberUserInfo(String token, String email) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
Expand Down Expand Up @@ -279,32 +277,6 @@ public void dismissLoadingDialog() {
mDialog.dismiss();
}

@Override
public void getRunTimePermissions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(LoginActivity.this,
Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.CAMERA,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.BLUETOOTH,
Manifest.permission.BLUETOOTH_ADMIN,
Manifest.permission.READ_CONTACTS,
Manifest.permission.WRITE_CONTACTS,
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.WAKE_LOCK,
Manifest.permission.INTERNET,
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.VIBRATE,

}, 0);
}
}
}

@Override
public void openSignUp() {
log.setVisibility(View.GONE);
Expand Down Expand Up @@ -468,4 +440,4 @@ public void onOtpCompleted(String otp) {
mOtpCode = otp;
mLoginPresenter.newPasswordInput();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ interface LoginView {
void showLoadingDialog();

void dismissLoadingDialog();

void getRunTimePermissions();

// void checkUserSession();

void openSignUp();

void openLogin();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package io.github.project_travel_mate.travel;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
Expand Down Expand Up @@ -94,7 +98,7 @@ protected void onCreate(Bundle savedInstanceState) {
mToken = mSharedPreferences.getString(USER_TOKEN, null);

fetchCitiesList();

getPermissions();
setTitle("Hotels");

selectCity.setOnClickListener(this);
Expand All @@ -111,6 +115,25 @@ protected void onCreate(Bundle savedInstanceState) {
}
}

//Get permissions for making calls and locations
private void getPermissions() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we would need runtime permissions for other places too (not just hotels?)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_CONTACTS,
Manifest.permission.WRITE_CONTACTS,
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
}, 0);
}
}
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home)
Expand Down Expand Up @@ -439,6 +462,8 @@ private HotelsViewHolder(View itemView) {
}
}



/**
* Plays the network lost animation in the view
*/
Expand Down