Skip to content

Commit

Permalink
code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahdi Hijazi committed Mar 24, 2017
1 parent f74bea3 commit c319b51
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
Expand Up @@ -67,7 +67,8 @@ public void onClick(View view)
if (savedInstanceState == null)
StartupHandler.HandleInit(this);

if(PermissionsHandler.hasWriteAccess(this)) {
if (PermissionsHandler.hasWriteAccess(this))
{
PlatformPagerAdapter platformPagerAdapter = new PlatformPagerAdapter(getFragmentManager(), this);
mViewPager.setAdapter(platformPagerAdapter);
} else {
Expand Down Expand Up @@ -170,6 +171,7 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in
break;
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
break;
}
}

Expand Down
Expand Up @@ -165,14 +165,16 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in
break;
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
break;
}
}

private void buildRowsAdapter()
{
mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());

if(PermissionsHandler.hasWriteAccess(this)) {
if (PermissionsHandler.hasWriteAccess(this))
{
loadGames();
}

Expand Down
Expand Up @@ -22,9 +22,9 @@ public static boolean checkWritePermission(final Activity activity) {
return true;
}

int hasWriteContactsPermission = ContextCompat.checkSelfPermission(activity, WRITE_EXTERNAL_STORAGE);
int hasWritePermission = ContextCompat.checkSelfPermission(activity, WRITE_EXTERNAL_STORAGE);

if (hasWriteContactsPermission != PackageManager.PERMISSION_GRANTED) {
if (hasWritePermission != PackageManager.PERMISSION_GRANTED) {
if (activity.shouldShowRequestPermissionRationale(WRITE_EXTERNAL_STORAGE)) {
showMessageOKCancel(activity, activity.getString(R.string.write_permission_needed),
new DialogInterface.OnClickListener() {
Expand All @@ -47,11 +47,11 @@ public void onClick(DialogInterface dialog, int which) {

public static boolean hasWriteAccess(Activity activity) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int hasWriteContactsPermission = ContextCompat.checkSelfPermission(activity, WRITE_EXTERNAL_STORAGE);
return hasWriteContactsPermission == PackageManager.PERMISSION_GRANTED;
} else {
return true;
int hasWritePermission = ContextCompat.checkSelfPermission(activity, WRITE_EXTERNAL_STORAGE);
return hasWritePermission == PackageManager.PERMISSION_GRANTED;
}

return true;
}

private static void showMessageOKCancel(final Activity activity, String message, DialogInterface.OnClickListener okListener) {
Expand Down
Expand Up @@ -50,7 +50,8 @@ public static void copyAssetsIfNeeded(Activity parent) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(parent);
boolean assetsCopied = preferences.getBoolean("assetsCopied", false);

if(!assetsCopied) {
if (!assetsCopied)
{
// Copy assets into appropriate locations.
Intent copyAssets = new Intent(parent, AssetCopyService.class);
parent.startService(copyAssets);
Expand Down

0 comments on commit c319b51

Please sign in to comment.