Search in sources :

Example 1 with Adapter_Javascript

use of de.baumann.browser.View.Adapter_Javascript in project browser by scoute-dich.

the class Whitelist_Javascript method onCreate.

@SuppressWarnings("ConstantConditions")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    helper_main.setTheme(this);
    setContentView(R.layout.whitelist);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    RecordAction action = new RecordAction(this);
    action.open(false);
    list = action.listDomainsJS();
    action.close();
    ListView listView = findViewById(R.id.whitelist);
    listView.setEmptyView(findViewById(R.id.whitelist_empty));
    adapter = new Adapter_Javascript(this, list);
    listView.setAdapter(adapter);
    adapter.notifyDataSetChanged();
    Button button = findViewById(R.id.whitelist_add);
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            EditText editText = findViewById(R.id.whitelist_edit);
            String domain = editText.getText().toString().trim();
            if (domain.isEmpty()) {
                NinjaToast.show(Whitelist_Javascript.this, R.string.toast_input_empty);
            } else if (!BrowserUnit.isURL(domain)) {
                NinjaToast.show(Whitelist_Javascript.this, R.string.toast_invalid_domain);
            } else {
                RecordAction action = new RecordAction(Whitelist_Javascript.this);
                action.open(true);
                if (action.checkDomainJS(domain)) {
                    NinjaToast.show(Whitelist_Javascript.this, R.string.toast_domain_already_exists);
                } else {
                    Javascript adBlock = new Javascript(Whitelist_Javascript.this);
                    adBlock.addDomain(domain.trim());
                    list.add(0, domain.trim());
                    adapter.notifyDataSetChanged();
                    NinjaToast.show(Whitelist_Javascript.this, R.string.toast_add_whitelist_successful);
                }
                action.close();
            }
        }
    });
}
Also used : EditText(android.widget.EditText) ListView(android.widget.ListView) Adapter_Javascript(de.baumann.browser.View.Adapter_Javascript) Button(android.widget.Button) Adapter_Javascript(de.baumann.browser.View.Adapter_Javascript) Javascript(de.baumann.browser.Browser.Javascript) RecordAction(de.baumann.browser.Database.RecordAction) TextView(android.widget.TextView) View(android.view.View) ListView(android.widget.ListView) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 Button (android.widget.Button)1 EditText (android.widget.EditText)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 Javascript (de.baumann.browser.Browser.Javascript)1 RecordAction (de.baumann.browser.Database.RecordAction)1 Adapter_Javascript (de.baumann.browser.View.Adapter_Javascript)1