use of com.amaze.filemanager.ui.fragments.DbViewerFragment in project AmazeFileManager by TeamAmaze.
the class DatabaseViewerActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_db_viewer);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
boolean useNewStack = getBoolean(PREFERENCE_TEXTEDITOR_NEWSTACK);
getSupportActionBar().setDisplayHomeAsUpEnabled(!useNewStack);
path = getIntent().getStringExtra("path");
pathFile = new File(path);
listView = findViewById(R.id.listView);
load(pathFile);
listView.setOnItemClickListener((parent, view, position, id) -> {
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
DbViewerFragment fragment = new DbViewerFragment();
Bundle bundle = new Bundle();
bundle.putString("table", arrayList.get(position));
fragment.setArguments(bundle);
fragmentTransaction.add(R.id.content_frame, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
});
initStatusBarResources(findViewById(R.id.parentdb));
}
use of com.amaze.filemanager.ui.fragments.DbViewerFragment in project AmazeFileManager by TeamAmaze.
the class DbViewerTaskTest method testCompleteTask.
@Test
public void testCompleteTask() {
SQLiteDatabase sqLiteDatabase = SQLiteDatabase.openDatabase("src/test/resources/test.db", null, SQLiteDatabase.OPEN_READONLY);
assertNotNull(sqLiteDatabase);
DbViewerFragment mock = mock(DbViewerFragment.class);
TextView loadingText = new TextView(ApplicationProvider.getApplicationContext());
mock.loadingText = loadingText;
mock.databaseViewerActivity = mock(DatabaseViewerActivity.class);
mock.loadingText.setVisibility(View.GONE);
when(mock.databaseViewerActivity.getAppTheme()).thenReturn(AppTheme.DARK);
Cursor schemaCursor = sqLiteDatabase.rawQuery("PRAGMA table_info('users');", null);
Cursor contentCursor = sqLiteDatabase.rawQuery("SELECT * FROM users", null);
DbViewerTask task = new DbViewerTask(schemaCursor, contentCursor, webView, mock);
task.onPreExecute();
task.doInBackground();
task.onPostExecute(null);
assertNotNull(task.stringBuilder.toString());
Document html = Jsoup.parse(task.stringBuilder.toString());
assertNotNull(html);
Elements elements = html.getElementsByTag("table");
assertEquals(1, elements.size());
elements = elements.get(0).getElementsByTag("tr");
assertEquals(5, elements.size());
Elements headerRow = elements.get(0).getElementsByTag("th");
assertEquals(3, headerRow.size());
sqLiteDatabase.close();
}
use of com.amaze.filemanager.ui.fragments.DbViewerFragment in project AmazeFileManager by TeamAmaze.
the class DbViewerTaskTest method testOnPreExecute.
@Test
public void testOnPreExecute() {
DbViewerFragment mock = mock(DbViewerFragment.class);
TextView loadingText = new TextView(ApplicationProvider.getApplicationContext());
mock.loadingText = loadingText;
mock.databaseViewerActivity = mock(DatabaseViewerActivity.class);
mock.loadingText.setVisibility(View.GONE);
when(mock.databaseViewerActivity.getAppTheme()).thenReturn(AppTheme.DARK);
DbViewerTask task = new DbViewerTask(null, null, webView, mock);
task.onPreExecute();
assertEquals(VISIBLE, mock.loadingText.getVisibility());
assertTrue(task.htmlInit.contains("color:#ffffff"));
assertEquals("utf-8", webView.getSettings().getDefaultTextEncodingName());
when(mock.databaseViewerActivity.getAppTheme()).thenReturn(AppTheme.BLACK);
task = new DbViewerTask(null, null, webView, mock);
task.onPreExecute();
assertEquals(VISIBLE, mock.loadingText.getVisibility());
assertTrue(task.htmlInit.contains("color:#ffffff"));
assertEquals("utf-8", webView.getSettings().getDefaultTextEncodingName());
when(mock.databaseViewerActivity.getAppTheme()).thenReturn(AppTheme.LIGHT);
task = new DbViewerTask(null, null, webView, mock);
task.onPreExecute();
assertEquals(VISIBLE, mock.loadingText.getVisibility());
assertTrue(task.htmlInit.contains("color:#000000"));
assertEquals("utf-8", webView.getSettings().getDefaultTextEncodingName());
}
use of com.amaze.filemanager.ui.fragments.DbViewerFragment in project AmazeFileManager by TeamAmaze.
the class DbViewerTaskTest method testExecute.
@Test
public void testExecute() {
SQLiteDatabase sqLiteDatabase = SQLiteDatabase.openDatabase("src/test/resources/test.db", null, SQLiteDatabase.OPEN_READONLY);
assertNotNull(sqLiteDatabase);
DbViewerFragment mock = mock(DbViewerFragment.class);
TextView loadingText = new TextView(ApplicationProvider.getApplicationContext());
mock.loadingText = loadingText;
Cursor schemaCursor = sqLiteDatabase.rawQuery("PRAGMA table_info('users');", null);
Cursor contentCursor = sqLiteDatabase.rawQuery("SELECT * FROM users", null);
DbViewerTask task = new DbViewerTask(schemaCursor, contentCursor, webView, mock);
task.doInBackground();
shadowOf(getMainLooper()).idle();
assertNotNull(task.schemaList);
assertNotNull(task.contentList);
// 3 columns
assertEquals(3, task.schemaList.size());
// 4 records
assertEquals(4, task.contentList.size());
assertEquals("4 records loaded", loadingText.getText().toString());
sqLiteDatabase.close();
}
Aggregations