Skip to content

Commit

Permalink
Import database fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jamorham committed Sep 19, 2016
1 parent 04d05be commit 029b4a7
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.eveningoutpost.dexdrip.Models.JoH;
import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter;
import com.eveningoutpost.dexdrip.utils.DatabaseUtil;
import com.eveningoutpost.dexdrip.utils.FileUtils;
Expand All @@ -36,6 +38,7 @@ public class ImportDatabaseActivity extends ListActivityWithMenu {
private Handler mHandler;
private ArrayList<String> databaseNames;
private ArrayList<File> databases;
private final static int MY_PERMISSIONS_REQUEST_STORAGE = 132;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -54,9 +57,10 @@ private void generateDBGui() {
sortDatabasesAlphabetically();
showDatabasesInList();
} else if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
JoH.static_toast_long("Need permission for saved files");
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
0);
MY_PERMISSIONS_REQUEST_STORAGE);
} else {
postImportDB("\'xdrip\' is not a directory... aborting.");
}
Expand Down Expand Up @@ -137,8 +141,9 @@ public boolean accept(File pathname) {
return pathname.getPath().endsWith(".sqlite");
}
});

Collections.addAll(databases, files);
if ((databases != null) && (files != null)) {
Collections.addAll(databases, files);
}
}

@Override
Expand Down Expand Up @@ -173,6 +178,18 @@ public String getMenuName() {
return menu_name;
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == MY_PERMISSIONS_REQUEST_STORAGE) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
generateDBGui();
} else {
finish();
}
}
}

public int getDBVersion() {

int version = -1;
Expand Down

0 comments on commit 029b4a7

Please sign in to comment.