Skip to content

Commit

Permalink
Merge pull request #95 from amitshekhariitbhu/development
Browse files Browse the repository at this point in the history
Merge from Development
  • Loading branch information
amitshekhariitbhu authored Jan 8, 2018
2 parents a31ad4e + eaedc64 commit 9bc28fb
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 29 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ public static void setCustomDatabaseFiles(Context context) {
Class<?> debugDB = Class.forName("com.amitshekhar.DebugDB");
Class[] argTypes = new Class[]{HashMap.class};
Method setCustomDatabaseFiles = debugDB.getMethod("setCustomDatabaseFiles", argTypes);
HashMap<String, File> customDatabaseFiles = new HashMap<>();
HashMap<String, Pair<File, String>> customDatabaseFiles = new HashMap<>();
// set your custom database files
customDatabaseFiles.put(ExtTestDBHelper.DATABASE_NAME,
new File(context.getFilesDir() + "/" + ExtTestDBHelper.DIR_NAME +
"/" + ExtTestDBHelper.DATABASE_NAME));
new Pair<>(new File(context.getFilesDir() + "/" + ExtTestDBHelper.DIR_NAME +
"/" + ExtTestDBHelper.DATABASE_NAME), ""));
setCustomDatabaseFiles.invoke(null, customDatabaseFiles);
} catch (Exception ignore) {

Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ android {
}
buildTypes {
debug {
resValue("string", "PORT_NUMBER", "8081")
resValue("string", "PORT_NUMBER", "8080")
resValue("string", "DB_PASSWORD_PERSON", "a_password")
}
release {
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/com/sample/database/PersonDBHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

package com.sample.database;

import android.app.Application;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

import net.sqlcipher.DatabaseUtils;
import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteOpenHelper;
Expand Down Expand Up @@ -110,7 +110,7 @@ public ArrayList<String> getAllPerson() {
while (!res.isAfterLast()) {
arrayList.add(
res.getString(res.getColumnIndex(PERSON_COLUMN_FIRST_NAME)) + " " +
res.getString(res.getColumnIndex(PERSON_COLUMN_LAST_NAME)));
res.getString(res.getColumnIndex(PERSON_COLUMN_LAST_NAME)));
res.moveToNext();
}
res.close();
Expand All @@ -128,8 +128,7 @@ public int count() {
} else {
return 0;
}
}
finally {
} finally {
cursor.close();
db.close();
}
Expand Down
7 changes: 3 additions & 4 deletions debug-db/src/main/java/com/amitshekhar/DebugDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
* Created by amitshekhar on 15/11/16.
Expand Down Expand Up @@ -74,12 +73,12 @@ public static void shutDown() {
}
}

public static void setCustomDatabaseFiles(HashMap<String, Pair<File, String>> customDatabaseFiles){
if(clientServer!=null){
public static void setCustomDatabaseFiles(HashMap<String, Pair<File, String>> customDatabaseFiles) {
if (clientServer != null) {
clientServer.setCustomDatabaseFiles(customDatabaseFiles);
}
}

public static boolean isServerRunning() {
return clientServer != null && clientServer.isRunning();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static class TableInfo {
public String title;
public boolean isPrimary;
}

public static class ColumnData {
public String dataType;
public Object value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.net.Socket;
import java.net.SocketException;
import java.util.HashMap;
import java.util.Map;

public class ClientServer implements Runnable {

Expand Down Expand Up @@ -88,8 +87,8 @@ public void run() {
}
}

public void setCustomDatabaseFiles(HashMap<String, Pair<File, String>> customDatabaseFiles){
mRequestHandler.setCustomDatabaseFiles(customDatabaseFiles);
public void setCustomDatabaseFiles(HashMap<String, Pair<File, String>> customDatabaseFiles) {
mRequestHandler.setCustomDatabaseFiles(customDatabaseFiles);
}

public boolean isRunning() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import android.content.Context;
import android.content.res.AssetManager;
import net.sqlcipher.database.SQLiteDatabase;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Pair;
Expand All @@ -39,6 +38,8 @@
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

import net.sqlcipher.database.SQLiteDatabase;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -155,7 +156,7 @@ public void handle(Socket socket) throws IOException {
}
}

public void setCustomDatabaseFiles(HashMap<String, Pair<File, String>> customDatabaseFiles){
public void setCustomDatabaseFiles(HashMap<String, Pair<File, String>> customDatabaseFiles) {
mCustomDatabaseFiles = customDatabaseFiles;
}

Expand Down Expand Up @@ -185,17 +186,17 @@ private void closeDatabase() {

private String getDBListResponse() {
mDatabaseFiles = DatabaseFileProvider.getDatabaseFiles(mContext);
if(mCustomDatabaseFiles!=null){
if (mCustomDatabaseFiles != null) {
mDatabaseFiles.putAll(mCustomDatabaseFiles);
}
Response response = new Response();
if (mDatabaseFiles != null) {
for (HashMap.Entry<String, Pair<File, String>> entry : mDatabaseFiles.entrySet()) {
String[] dbEntry = { entry.getKey(), entry.getValue().second != "" ? "true" : "false" };
String[] dbEntry = {entry.getKey(), !entry.getValue().second.equals("") ? "true" : "false"};
response.rows.add(dbEntry);
}
}
response.rows.add(new String[] { Constants.APP_SHARED_PREFERENCES, "false" });
response.rows.add(new String[]{Constants.APP_SHARED_PREFERENCES, "false"});
response.isSuccessful = true;
return mGson.toJson(response);
}
Expand Down Expand Up @@ -238,7 +239,7 @@ private String executeQueryAndGetResponse(String route) {
if (query != null) {
String[] statements = query.split(";");

for (int i=0; i<statements.length; i++) {
for (int i = 0; i < statements.length; i++) {

String aQuery = statements[i].trim();
first = aQuery.split(" ")[0].toLowerCase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@
package com.amitshekhar.utils;

import android.content.Context;
import android.content.res.Resources;
import android.util.Pair;

import com.amitshekhar.R;

import java.io.File;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.List;

/**
* Created by amitshekhar on 06/02/17.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
package com.amitshekhar.utils;

import android.content.ContentValues;

import net.sqlcipher.Cursor;
import net.sqlcipher.database.SQLiteDatabase;
import android.text.TextUtils;
import android.util.Log;

import com.amitshekhar.model.Response;
import com.amitshekhar.model.RowDataRequest;
import com.amitshekhar.model.TableDataResponse;
import com.amitshekhar.model.UpdateRowResponse;

import net.sqlcipher.Cursor;
import net.sqlcipher.database.SQLiteDatabase;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand Down

0 comments on commit 9bc28fb

Please sign in to comment.