Revision 5debefcb

View differences:

app/src/org/storymaker/app/BaseActivity.java
1 1
package org.storymaker.app;
2 2

  
3
import android.Manifest;
3 4
import android.app.Activity;
4 5
import android.app.Notification;
5 6
import android.content.Context;
......
14 15
import android.os.Bundle;
15 16
import android.preference.PreferenceManager;
16 17
import android.support.v4.app.ActionBarDrawerToggle;
18
import android.support.v4.app.ActivityCompat;
17 19
import android.support.v4.app.FragmentActivity;
18 20
import android.support.v4.app.NotificationCompat;
19 21
import android.support.v4.widget.DrawerLayout;
......
35 37

  
36 38
import java.io.IOException;
37 39
import java.io.InputStream;
40
import java.util.ArrayList;
38 41

  
39 42
import info.guardianproject.cacheword.CacheWordHandler;
40 43
import info.guardianproject.cacheword.ICacheWordSubscriber;
......
428 431
        if (mDrawerOpen) mDrawerLayout.closeDrawer(mDrawerContainer);
429 432
        else mDrawerLayout.openDrawer(mDrawerContainer);
430 433
    }
434

  
435
    // force permissions we require
436
    protected void checkAndEnforcePermissions() {
437
        ArrayList<String> perms = new ArrayList<>();
438

  
439
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
440
            perms.add(Manifest.permission.READ_EXTERNAL_STORAGE);
441
        }
442
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
443
            perms.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
444
        }
445
        if (perms.size() > 0) {
446
            ActivityCompat.requestPermissions(this, perms.toArray(new String[0]), Constants.PERMS_REQ_ALL);
447
        }
448
    }
431 449
}
app/src/org/storymaker/app/BaseHomeActivity.java
1 1
package org.storymaker.app;
2 2

  
3
import android.Manifest;
3 4
import android.app.AlertDialog;
4 5
import android.app.ProgressDialog;
5 6
import android.content.ComponentName;
......
12 13
import android.os.AsyncTask;
13 14
import android.os.Bundle;
14 15
import android.preference.PreferenceManager;
16
import android.support.v4.app.ActivityCompat;
15 17
import android.support.v4.view.ViewPager;
16 18
import android.support.v7.widget.RecyclerView;
17 19
import android.util.Log;
......
814 816
                showLauncherIcon();
815 817
            }
816 818
        }
819

  
820
        checkAndEnforcePermissions(); // FIXME we should handle these at time of use instead of like this
817 821
    }
818 822

  
819 823
    protected void showSPLSelectorPopup(final String[] names, final String[] paths) {
app/src/org/storymaker/app/Constants.java
18 18
    public static final String PREFS_APP_TITLE = "PREFS_APP_TITLE";
19 19

  
20 20
    public static final int APP_MIGRATION_VERSION = 1;
21

  
22
    public static final int PERMS_REQ_ALL = 1;
23
    public static final int PERMS_REQ_READ_EXTERNAL_STORAGE = 2;
24
    public static final int PERMS_REQ_WRITE_EXTERNAL_STORAGE = 3;
21 25
}

Also available in: Unified diff