Search in sources :

Example 1 with DbViewerFragment

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));
}
Also used : DbViewerFragment(com.amaze.filemanager.ui.fragments.DbViewerFragment) FragmentTransaction(androidx.fragment.app.FragmentTransaction) Bundle(android.os.Bundle) File(java.io.File)

Example 2 with DbViewerFragment

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();
}
Also used : DbViewerFragment(com.amaze.filemanager.ui.fragments.DbViewerFragment) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) DatabaseViewerActivity(com.amaze.filemanager.ui.activities.DatabaseViewerActivity) TextView(android.widget.TextView) Cursor(android.database.Cursor) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Example 3 with DbViewerFragment

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());
}
Also used : DbViewerFragment(com.amaze.filemanager.ui.fragments.DbViewerFragment) DatabaseViewerActivity(com.amaze.filemanager.ui.activities.DatabaseViewerActivity) TextView(android.widget.TextView) Test(org.junit.Test)

Example 4 with DbViewerFragment

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();
}
Also used : DbViewerFragment(com.amaze.filemanager.ui.fragments.DbViewerFragment) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) TextView(android.widget.TextView) Cursor(android.database.Cursor) Test(org.junit.Test)

Aggregations

DbViewerFragment (com.amaze.filemanager.ui.fragments.DbViewerFragment)4 TextView (android.widget.TextView)3 Test (org.junit.Test)3 Cursor (android.database.Cursor)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 DatabaseViewerActivity (com.amaze.filemanager.ui.activities.DatabaseViewerActivity)2 Bundle (android.os.Bundle)1 FragmentTransaction (androidx.fragment.app.FragmentTransaction)1 File (java.io.File)1 Document (org.jsoup.nodes.Document)1 Elements (org.jsoup.select.Elements)1