/** * Called when one of the cards is swiped away. Removes the associated book from the recents list. * * @param uniqueId The unique ID of the item so that the correct {@link RBook} can be retrieved. */ @Override public void handleSwiped(long uniqueId) { // Remove from recents. realm.executeTransactionAsync( bgRealm -> bgRealm.where(RBook.class).equalTo("uniqueId", uniqueId).findFirst().isInRecents = false); // Show snackbar with "Undo" button. Snackbar undoSnackbar = Snackbar.make(coordinator, R.string.book_removed, Snackbar.LENGTH_LONG); undoSnackbar.setAction( R.string.undo, view -> { // Put back in recents if undo button is clicked. try (Realm realm = Realm.getDefaultInstance()) { realm.executeTransactionAsync( bgRealm -> bgRealm .where(RBook.class) .equalTo("uniqueId", uniqueId) .findFirst() .isInRecents = true); } }); undoSnackbar.show(); }
/** Remove todos os objetos RealmVideo salvos no banco. */ public static void cleanVideos() { Realm realm = Realm.getDefaultInstance(); RealmResults<RealmVideo> results = realm.where(RealmVideo.class).findAll(); realm.beginTransaction(); results.clear(); realm.commitTransaction(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_edit_memo); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); saveButton = (ImageButton) findViewById(R.id.bottom_save); editText = (EditText) findViewById(R.id.memo_edit); editText.addTextChangedListener(this); String htmlText = getIntent().getStringExtra(EXTRA_HTMLTEXT); editText.setText(TextConverter.toCharSequence(htmlText, editText)); editText.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { editText.setCursorVisible(true); } }); long memoTime = getIntent().getLongExtra(EXTRA_TIME, 0); memoId = getIntent().getLongExtra(EXTRA_MEMO_ID, 0); memoDateTime = Calendar.getInstance(); memoDateTime.setTime(new Date(memoTime)); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); updateTitle(); realm = Realm.getDefaultInstance(); memoBo = new MemoBo(realm); tagPopupMenuHelper = new TagPopupMenuHelper(this, realm, editText); updateSaveButton(false); }
@Override protected void onHandleIntent(Intent intent) { Log.e(TAG, "getting notifications. . . "); String username = intent.getStringExtra(Constants.User.USERNAME); TBSUserInterface service = ServiceManager.getInstance(); try { Call<List<Notification>> call = service.getNotifications(username); Response<List<Notification>> response = call.execute(); if (response.code() == HttpURLConnection.HTTP_OK) { List<Notification> notifications = response.body(); Log.e(TAG, response.body().toString()); Realm realm = Realm.getDefaultInstance(); realm.beginTransaction(); realm.where(Notification.class).findAll().clear(); realm.copyToRealmOrUpdate(notifications); realm.commitTransaction(); realm.close(); notifySuccess(ACTION, "Successful"); } else { String error = response.errorBody().string(); Log.e(TAG, "Error: " + error); notifyFailure(ACTION, "Error"); } } catch (IOException e) { Log.e(TAG, e.getMessage(), e); notifyFailure(ACTION, "Unable to connect to server"); } }
public void getFlowDefinition(final DBFlow flow, final Callback<Definitions> callback) { final Realm realm = Realm.getDefaultInstance(); realm.beginTransaction(); flow.setFetching(true); realm.commitTransaction(); m_api .getFlowDefinition(getToken(), flow.getUuid()) .enqueue( new Callback<Definitions>() { @Override public void onResponse( final Call<Definitions> call, final Response<Definitions> response) { checkResponse(response); realm.beginTransaction(); flow.setFetching(false); realm.commitTransaction(); realm.close(); callback.onResponse(call, response); } @Override public void onFailure(Call<Definitions> call, Throwable t) { realm.beginTransaction(); flow.setFetching(false); realm.commitTransaction(); realm.close(); callback.onFailure(call, t); } }); }
@Override protected void onHandleIntent(Intent intent) { Log.e(TAG, "gettting donation requests"); TbsService service = ServiceManager.getInstance(); try { Call<List<DonateApproval>> call = service.getDonationRequests(); Response<List<DonateApproval>> response = call.execute(); if (response.code() == HttpURLConnection.HTTP_OK) { List<DonateApproval> donateApprovals = response.body(); Realm realm = Realm.getDefaultInstance(); realm.beginTransaction(); realm.where(DonateApproval.class).findAll().clear(); realm.copyToRealmOrUpdate(donateApprovals); realm.commitTransaction(); realm.close(); notifySuccess(ACTION, "Successful"); } else { String error = response.errorBody().string(); Log.e(TAG, "Error: " + error); notifyFailure(ACTION, "Failed"); } } catch (Exception e) { Log.e(TAG, e.getMessage(), e); notifyFailure(ACTION, "Request error"); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sleep); Realm realm = Realm.getDefaultInstance(); Toolbar tb = (Toolbar) findViewById(R.id.toolbar); tb.setTitle("Sleep Summaries"); setSupportActionBar(tb); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha); upArrow.setColorFilter(Color.parseColor("#FFFFFF"), PorterDuff.Mode.SRC_ATOP); getSupportActionBar().setHomeAsUpIndicator(upArrow); tb.setTitleTextColor(Color.WHITE); } tb.setNavigationOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); // Get all sleep data recorded and send this to adapter to populate the list RealmResults<Sleep> sleeps = realm.where(Sleep.class).findAll(); sleeps.sort("startTime", Sort.DESCENDING); SleepAdapter sleepAdapter = new SleepAdapter(this, R.id.listView, sleeps, true); ListView listView = (ListView) findViewById(R.id.listView); listView.setAdapter(sleepAdapter); }
public LocalDailyCacheManagerImpl(Context context) { RealmConfiguration config = new RealmConfiguration.Builder(context) .name("org.theotech.ceaselessandroid") .schemaVersion(0) .deleteRealmIfMigrationNeeded() .build(); Realm.setDefaultConfiguration(config); this.realm = Realm.getDefaultInstance(); }
public boolean checkIfTaskIsAdded(String taskName, String taskDescription) { Realm realm = Realm.getDefaultInstance(); RealmResults<Task> getTasks = realm .where(Task.class) .equalTo("name", taskName) .equalTo("description", taskDescription) .findAll(); boolean isAdded = getTasks.size() > 0; realm.close(); return isAdded; }
private void initRealm() { RealmConfiguration realmConfiguration = new RealmConfiguration.Builder(getApplicationContext()) .name(getString(R.string.db_name)) .schemaVersion(getResources().getInteger(R.integer.db_version)) .build(); Realm.setDefaultConfiguration(realmConfiguration); Realm realm = Realm.getDefaultInstance(); GroupRepository.createDefaultGroups(realm); realm.close(); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = container.getRootView(); mContext = getContext(); Realm.setDefaultConfiguration(MainActivity.mRealmConfig); try { mRealm = Realm.getDefaultInstance(); } catch (RealmMigrationNeededException e) { MainActivity.mRealmConfig = new RealmConfiguration.Builder(getActivity()).deleteRealmIfMigrationNeeded().build(); Realm.setDefaultConfiguration(MainActivity.mRealmConfig); mRealm = Realm.getDefaultInstance(); } // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_number_group, container, false); }
private void truncateModuleLocal() { // instance realm Realm realm = Realm.getDefaultInstance(); // delete old data if exists final RealmResults<ModuleLocalModel> moduleLocalModels = realm.where(ModuleLocalModel.class).findAll(); realm.executeTransaction( new Realm.Transaction() { @Override public void execute(Realm realm) { // Delete all matches moduleLocalModels.deleteAllFromRealm(); } }); }
public void updateFinished(OpenweathermapObject data) { String errorMessage = getString(R.string.txt_unknown_error); if (data != null) { errorMessage = data.getErrorMessage(); } if (errorMessage.isEmpty()) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); Boolean del_old = preferences.getBoolean( getString(R.string.settings_delete_old_data_key), getResources().getBoolean(R.bool.settings_delete_old_data_default)); Realm realm = null; try { realm = Realm.getDefaultInstance(); realm.beginTransaction(); if (del_old) { Long timeStamp = data.getWeatherForecastList().get(0).getTimeStamp(); RealmResults<ForecastListItem> result = realm.where(ForecastListItem.class).lessThan("timeStamp", timeStamp).findAll(); result.clear(); } realm.copyToRealmOrUpdate(data.getWeatherForecastList()); realm.commitTransaction(); SharedPreferences.Editor editor = preferences.edit(); editor.putLong(getString(R.string.last_update_key), System.currentTimeMillis()); String city = data.getCityName().concat(", ".concat(data.getCountry())); editor.putString(getString(R.string.current_city_key), city); editor.commit(); } finally { if (realm != null) { realm.close(); } } } Intent intent = new Intent(BROADCAST_ACTION); intent.putExtra(PARAM_STATUS, STATUS_FINISH); intent.putExtra(PARAM_RESULT, errorMessage); sendBroadcast(intent); }
public void loadToRealm() throws JSONException, ParseException { int count = JSONlist.length(); Realm realm = Realm.getDefaultInstance(); realm.beginTransaction(); realm.clear(MyRealmItem.class); for (int i = 0; i < count; i++) { MyWeatherItem myWeatherItem = new MyWeatherItem((JSONObject) JSONlist.get(i)); realm.copyToRealmOrUpdate(myWeatherItem.realmItem); } realm.commitTransaction(); RealmQuery<MyRealmItem> query = realm.where(MyRealmItem.class); results = query.findAll(); if (adapter != null) { adapter.notifyDataSetChanged(); } // realm.close(); }
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Read prefs to fill in vars. readPrefs(); // Get Realm. realm = Realm.getDefaultInstance(); initUi(); // If we have a saved instance state, check to see if we were in action mode. if (savedInstanceState != null && savedInstanceState.getBoolean(C.IS_IN_ACTION_MODE)) { // If we were in action mode, restore the adapter's state and start action mode. adapter.restoreInstanceState(savedInstanceState); startActionMode(); } }
protected void onPostExecute(final JSONObject result) { if (result != null && result.has("version")) { // convert json to class final DocsModel docsModel = new Gson().fromJson(result.toString(), DocsModel.class); // truncate module local truncateModuleLocal(); for (ModuleModel moduleModel : docsModel.getModules()) { /// instance realm Realm realm = Realm.getDefaultInstance(); realm.beginTransaction(); // instance moduleLocalModel ModuleLocalModel moduleLocalModel = realm.createObject(ModuleLocalModel.class); // set title moduleLocalModel.setTitle(moduleModel.getTitle()); // set name moduleLocalModel.setName(moduleModel.getName()); realm.commitTransaction(); } DownloadDocs.setAdapterListener( new DownloadDocs.AdapterListener() { @Override public void onReady(boolean status) { // call onReady if (adapterListener != null) { Remember.putString(Config.NODE_JS_VERSION, docsModel.getVersion()); adapterListener.onReady(result); } } }); new DownloadDocs().execute(); } else { // call onError if (adapterListener != null) { adapterListener.onError(500); } } }
@SuppressWarnings("ButterKnifeInjectNotCalled") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; ArrayList<ContentItem> objects = new ArrayList<>(); objects.add( new ContentItem(getString(R.string.realm_ci_0_name), getString(R.string.realm_ci_0_desc))); objects.add( new ContentItem(getString(R.string.realm_ci_1_name), getString(R.string.realm_ci_1_desc))); objects.add( new ContentItem(getString(R.string.realm_ci_2_name), getString(R.string.realm_ci_2_desc))); objects.add( new ContentItem(getString(R.string.realm_ci_3_name), getString(R.string.realm_ci_3_desc))); objects.add( new ContentItem(getString(R.string.realm_ci_4_name), getString(R.string.realm_ci_4_desc))); objects.add( new ContentItem(getString(R.string.realm_ci_5_name), getString(R.string.realm_ci_5_desc))); objects.add( new ContentItem(getString(R.string.realm_ci_6_name), getString(R.string.realm_ci_6_desc))); objects.add( new ContentItem(getString(R.string.realm_ci_7_name), getString(R.string.realm_ci_7_desc))); objects.add( new ContentItem(getString(R.string.realm_ci_8_name), getString(R.string.realm_ci_8_desc))); MyAdapter adapter = new MyAdapter(this, objects); lv.setAdapter(adapter); View footer = LayoutInflater.from(this).inflate(R.layout.tip_end, null); lv.addFooterView(footer); Realm.init(this); // Create a RealmConfiguration that saves the Realm file in the app's "files" directory. RealmConfiguration realmConfig = new RealmConfiguration.Builder().build(); Realm.setDefaultConfiguration(realmConfig); Realm realm = Realm.getDefaultInstance(); realm.beginTransaction(); realm.deleteAll(); realm.commitTransaction(); }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (getArguments() != null) { monster = getArguments().getParcelable("monster"); } realm = Realm.getDefaultInstance(); favorite.setChecked(monster.isFavorite()); if (monster.isFavorite()) { choiceRadioGroup.getChildAt(choiceRadioGroup.getChildCount() - 1).setEnabled(false); } else { choiceRadioGroup.getChildAt(choiceRadioGroup.getChildCount() - 1).setEnabled(true); } favorite.setOnCheckedChangeListener(favoriteCheckListener); setupEvolutions(); evolutionSpinnerAdapter = new EvolutionSpinnerAdapter( getActivity(), R.layout.evolution_spinner_row, monster, evolutions); evolutionSpinner.setAdapter(evolutionSpinnerAdapter); choiceRadioGroup.setOnCheckedChangeListener(radioGroupCheckChangeListener); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add_update_discipline); discipline = new Discipline(); etName = (EditText) findViewById(R.id.et_name); TextView tvTitle = (TextView) findViewById(R.id.tv_title); Button btAddUpdate = (Button) findViewById(R.id.bt_add_update); realm = Realm.getDefaultInstance(); disciplines = realm.where(Discipline.class).findAll(); if (getIntent() != null && getIntent().getLongExtra(Discipline.ID, 0) > 0) { discipline.setId(getIntent().getLongExtra(Discipline.ID, 0)); discipline = disciplines.where().equalTo("id", discipline.getId()).findAll().get(0); etName.setText(discipline.getName()); tvTitle.setText("Atualizar disciplina"); btAddUpdate.setText("Update"); } }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (getArguments() != null) { enemy = Parcels.unwrap(getArguments().getParcelable("enemy")); } preferences = PreferenceManager.getDefaultSharedPreferences(Singleton.getInstance().getContext()); isGrid = preferences.getBoolean("isGrid", true); realm = Realm.getDefaultInstance(); if (monsterListAll == null) { monsterListAll = new ArrayList<>(); } monsterListAll.clear(); monsterListAll.addAll(realm.where(BaseMonster.class).greaterThan("monsterId", 0).findAll()); if (monsterList == null) { monsterList = new ArrayList<>(); } fastScroller.setRecyclerView(monsterListView); if (isGrid) { monsterListView.setLayoutManager( new StaggeredGridLayoutManager(5, StaggeredGridLayoutManager.VERTICAL)); } else { monsterListView.setLayoutManager( new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL)); } monsterPortraitListRecycler = new MonsterPortraitListRecycler( getContext(), monsterList, monsterListView, isGrid, realm, enemy); monsterListView.setAdapter(monsterPortraitListRecycler); getActivity().setTitle("Select Portrait"); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add_agent); ButterKnife.bind(this); settings = getSharedPreferences(Constants.PREFERENCES_SAM, 0); realm = Realm.getDefaultInstance(); toolbar.setTitle(R.string.add_agent); setSupportActionBar(toolbar); adapterAgent = new AgentAutocompleterAdapter(this, R.layout.agent_autocomplete_item); agentAgent.setAdapter(adapterAgent); agentAgent.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View view, int position, long id) { Integer temp = adapterAgent.getItem(position); agent = realm.where(Agent.class).equalTo(Constants.ID, temp.intValue()).findFirst(); agentAgent.setText(agent.getName()); } }); adapterInstitution = new InstitutionAutocompleterAdapter(this, R.layout.institution_autocomplete_item); agentInstitution.setAdapter(adapterInstitution); agentInstitution.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View view, int position, long id) { Integer temp = adapterInstitution.getItem(position); institution = realm.where(Institution.class).equalTo(Constants.ID, temp.intValue()).findFirst(); agentInstitution.setText(institution.getName()); } }); if (settings.getInt(Constants.DEFAULT_AGENT_ID, 0) > 0) { agent = realm .where(Agent.class) .equalTo(Constants.ID, settings.getInt(Constants.DEFAULT_AGENT_ID, 0)) .findFirst(); agentAgent.setText(agent.getName()); institution = realm .where(Institution.class) .equalTo(Constants.ID, settings.getInt(Constants.DEFAULT_INSTITUTION_ID, 0)) .findFirst(); agentInstitution.setText(institution.getName()); } agentAdd.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { int countErrors = 0; if (agentAgent.getText().length() < 2) { countErrors++; agentAgent.setError("El representante es requerido"); } if (agentInstitution.getText().length() < 2) { countErrors++; agentInstitution.setError("La institución es requerida"); } if (agent == null) { countErrors++; agentAgent.setError("El representante es incorrecto"); } if (institution == null) { countErrors++; agentInstitution.setError("La institución es incorrecta"); } if (countErrors == 0) { SharedPreferences settings = getApplicationContext().getSharedPreferences(Constants.PREFERENCES_SAM, 0); SharedPreferences.Editor editor = settings.edit(); editor.putInt(Constants.DEFAULT_AGENT_ID, agent.getId()); editor.putInt(Constants.DEFAULT_INSTITUTION_ID, institution.getId()); editor.commit(); Intent intent = new Intent(); if (getParent() == null) { setResult(Activity.RESULT_OK, intent); } else { getParent().setResult(Activity.RESULT_OK, intent); } finish(); } } }); agentCancel.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { SharedPreferences settings = getApplicationContext().getSharedPreferences(Constants.PREFERENCES_SAM, 0); SharedPreferences.Editor editor = settings.edit(); editor.putInt(Constants.DEFAULT_AGENT_ID, 0); editor.putInt(Constants.DEFAULT_INSTITUTION_ID, 0); editor.apply(); Intent intent = new Intent(); if (getParent() == null) { setResult(Activity.RESULT_CANCELED, intent); } else { getParent().setResult(Activity.RESULT_CANCELED, intent); } finish(); } }); }
void truncateRealm() { Realm realm = Realm.getDefaultInstance(); realm.beginTransaction(); realm.clear(RealmCharacter.class); realm.commitTransaction(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_cadastro_transporte); realm = Realm.getDefaultInstance(); transportes = realm.where(Transporte.class).findAll(); collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); collapsingToolbarLayout.setTitle("Serviço"); Toolbar toolbar = (Toolbar) findViewById(R.id.detalhe_toolbar); toolbar.setTitle("Serviço"); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); modelo = (EditText) findViewById(R.id.edt_modelo); marca = (EditText) findViewById(R.id.edt_marca); ano = (EditText) findViewById(R.id.edt_ano); km = (EditText) findViewById(R.id.edt_km); potencia = (EditText) findViewById(R.id.edt_potencia); rgTipo = (RadioGroup) findViewById(R.id.rgTipo); imagem = (ImageView) findViewById(R.id.tb_imagem); btSalvar = (Button) findViewById(R.id.bt_salvar_transporte); rgTipo.setOnCheckedChangeListener( new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.rb_carro: imagem.setImageResource(R.drawable.carro); imagemSelecionada = R.drawable.carro; break; case R.id.rb_moto: imagem.setImageResource(R.drawable.moto); imagemSelecionada = R.drawable.moto; break; case R.id.rb_caminhao: imagem.setImageResource(R.drawable.caminao); imagemSelecionada = R.drawable.caminao; break; case R.id.rb_aviao: imagem.setImageResource(R.drawable.aviao); imagemSelecionada = R.drawable.aviao; break; } } }); transporte = new Transporte(); if (getIntent() != null && getIntent().getLongExtra(Transporte.ID, 0) > 0) { transporte.setId(getIntent().getLongExtra(Transporte.ID, 0)); transporte = transportes.where().equalTo("id", transporte.getId()).findFirst(); modelo.setText(transporte.getModelo()); marca.setText(transporte.getMarca()); ano.setText(String.valueOf(transporte.getAno())); km.setText(String.valueOf(transporte.getKm())); potencia.setText(String.valueOf(transporte.getPotencia())); rgTipo.check(transporte.getTipo()); imagem.setImageResource(transporte.getImagem()); btSalvar.setText("Atualizar"); } btSalvar.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { try { if (validarCampos()) { realm.beginTransaction(); preencherDados(transporte); realm.copyToRealmOrUpdate(transporte); realm.commitTransaction(); // Script de serviços if (getIntent().getLongExtra(Transporte.ID, 0) == 0) { Transporte tranporte = realm.where(Transporte.class).findFirst(); String descricao = "Oleo"; int img = R.drawable.oleo; for (int i = 0; i < 3; i++) { realm.beginTransaction(); Servicos servico = new Servicos(); servico.setId(i + 1); servico.setDescricao(descricao); servico.setUltimaTroca(tranporte.getKm()); servico.setPeriodo(1); servico.setProximaTroca( servico.getUltimaTroca() + (servico.getPeriodo() * 1000)); servico.setData(new Date()); servico.setImagem(img); realm.copyToRealmOrUpdate(servico); realm.commitTransaction(); if (i == 0) { descricao = "Pneu"; img = R.drawable.roda; } else if (i == 1) { descricao = "Manutenção"; img = R.drawable.manutencao; } } } msg("Dados salvo"); EventBus.getDefault().post(transporte); finish(); } } catch (Exception e) { msg("erro " + e.getMessage()); } } }); }
@Override protected void onResume() { realm = Realm.getDefaultInstance(); super.onResume(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); preferences = PreferenceManager.getDefaultSharedPreferences(this); preferences.registerOnSharedPreferenceChangeListener(this); Settings settings = SettingsUtil.getSettings(this); preferences .edit() .putBoolean(SettingsUtil.ENABLE_UPDATES, settings.isUpdatesEnabled()) .putBoolean(SettingsUtil.KEY_BOUNDING_BOX, settings.isBoundingBoxEnabled()) .putString(SettingsUtil.SCAN_VALUE, String.valueOf(settings.getScanValue())) .putBoolean(SettingsUtil.SHOW_ONLY_LURED, settings.isShowOnlyLured()) .putBoolean(SettingsUtil.SHOW_GYMS, settings.isGymsEnabled()) .putBoolean(SettingsUtil.SHOW_POKESTOPS, settings.isPokestopsEnabled()) .putBoolean(SettingsUtil.SHOW_LURED_POKEMON, settings.isShowLuredPokemon()) .putBoolean(SettingsUtil.KEY_LOCK_GPS, settings.isLockGpsEnabled()) .putBoolean(SettingsUtil.KEY_OLD_MARKER, settings.isUseOldMapMarker()) .putString(SettingsUtil.SERVER_REFRESH_RATE, String.valueOf(settings.getServerRefresh())) .putString(SettingsUtil.MAP_REFRESH_RATE, String.valueOf(settings.getMapRefresh())) .putString(SettingsUtil.POKEMON_ICON_SCALE, String.valueOf(settings.getScale())) .putString(SettingsUtil.LAST_USERNAME, settings.getLastUsername()) .putBoolean(SettingsUtil.SHUFFLE_ICONS, settings.isShuffleIcons()) .commit(); addPreferencesFromResource(R.xml.settings); realm = Realm.getDefaultInstance(); scan_dialog = (Preference) getPreferenceManager().findPreference("scan_dialog"); scan_dialog.setOnPreferenceClickListener( new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { SettingsUtil.searchRadiusDialog(SettingsActivity.this); return true; } }); gym_filter = (Preference) getPreferenceManager().findPreference("gym_filter"); gym_filter.setOnPreferenceClickListener( new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { GymFilters.showGymFiltersDialog(SettingsActivity.this); return true; } }); expiration_filter = (Preference) getPreferenceManager().findPreference("expiration_filter"); expiration_filter.setOnPreferenceClickListener( new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { ExpirationFilters.showExpirationFiltersDialog(SettingsActivity.this); return true; } }); pokemon_blacklist = (Preference) getPreferenceManager().findPreference("pokemon_blacklist"); pokemon_blacklist.setOnPreferenceClickListener( new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { Intent filterIntent = new Intent(SettingsActivity.this, BlacklistActivity.class); startActivity(filterIntent); return true; } }); pokemon_whitelist = (Preference) getPreferenceManager().findPreference("pokemon_whitelist"); pokemon_whitelist.setOnPreferenceClickListener( new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { Intent filterIntent = new Intent(SettingsActivity.this, WhitelistActivity.class); startActivity(filterIntent); return true; } }); clear_gyms = (Preference) getPreferenceManager().findPreference("clear_gyms"); clear_gyms.setOnPreferenceClickListener( new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { realm.executeTransaction( new Realm.Transaction() { @Override public void execute(Realm realm) { if (realm.where(Gym.class).findAll().deleteAllFromRealm()) { Toast.makeText( SettingsActivity.this, getString(R.string.gyms_cleared), Toast.LENGTH_SHORT) .show(); } } }); return true; } }); clear_pokemon = (Preference) getPreferenceManager().findPreference("clear_pokemon"); clear_pokemon.setOnPreferenceClickListener( new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { realm.executeTransaction( new Realm.Transaction() { @Override public void execute(Realm realm) { if (realm.where(Pokemons.class).findAll().deleteAllFromRealm()) { Toast.makeText( SettingsActivity.this, getString(R.string.pokemon_cleared), Toast.LENGTH_SHORT) .show(); } } }); return true; } }); clear_pokestops = (Preference) getPreferenceManager().findPreference("clear_pokestops"); clear_pokestops.setOnPreferenceClickListener( new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { realm.executeTransaction( new Realm.Transaction() { @Override public void execute(Realm realm) { if (realm.where(PokeStop.class).findAll().deleteAllFromRealm()) { Toast.makeText( SettingsActivity.this, getString(R.string.pokestops_cleared), Toast.LENGTH_SHORT) .show(); } } }); return true; } }); logout = (Preference) getPreferenceManager().findPreference("logout"); logout.setOnPreferenceClickListener( new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { logOut(); return true; } }); update = (Preference) getPreferenceManager().findPreference("update"); update.setOnPreferenceClickListener( new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { new AppUpdateLoader().start(); return true; } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); realm = Realm.getDefaultInstance(); }
@Override public void onStart() { super.onStart(); mRealm = Realm.getDefaultInstance(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_event_detail); sharedPref = getApplicationContext().getSharedPreferences("PREFERENCE_FILE_KEY", Context.MODE_PRIVATE); ButterKnife.bind(this); Bundle extras = getIntent().getExtras(); _container_summary.setVisibility(View.VISIBLE); _container_artist.setVisibility(View.GONE); _container_venue.setVisibility(View.GONE); _summary_description.setVisibility(View.GONE); _summary_tickets_buy.setVisibility(View.GONE); _artist_websites.setVisibility(View.GONE); _artist_description.setVisibility(View.GONE); _venue_address.setVisibility(View.GONE); String eventID = "1038341"; // default should return 'Katie Melua' event String artistID = ""; String venueID = ""; if (extras != null) { eventID = extras.getString("EventID"); } // _baseLayout.setOnTouchListener(this); // ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) // _baseLayout.getLayoutParams(); // anchorLeft = _baseLayout.getLeft() + lp.leftMargin; myRealm = Realm.getDefaultInstance(); final Event event = myRealm.where(Event.class).equalTo("id", eventID).findFirst(); final Artist artist = myRealm.where(Artist.class).equalTo("id", event.getArtist().getId()).findFirst(); Log.d("Artist", artist.toString()); final Venue venue = myRealm.where(Venue.class).equalTo("id", event.getVenue().getId()).findFirst(); Log.d("Venue", venue.toString()); artistID = artist.getId(); venueID = venue.getId(); setEventData(eventID); setArtistData(artistID); setVenueData(venueID); Log.d("Event", event.getArtist().getName()); Log.d("Partial Data", event.toString()); _summary_tickets_buy.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { try { if (event.getUrl() != null) { Toast.makeText(getApplicationContext(), "Show me dem tickets!", Toast.LENGTH_SHORT) .show(); Log.d("Buying", event.getUrl()); Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(event.getUrl())); startActivity(browserIntent); } else { Toast.makeText(getApplicationContext(), "No ticket link :(", Toast.LENGTH_SHORT) .show(); Log.d("Else", event.getUrl()); } } catch (Exception e) { Log.d("Catch", e.toString()); } } }); // Check if realm already has full event data (via EventURL), if not, make volley request try { if (event.getUrl() == null) { // TODO: needs to update to get latest ticket info, maybe a timestamp check to // be added/separate api route for ticket info requestFullData(eventID, "Event"); Log.d(TAG, "Requesting full data..."); } else { Log.d(TAG, "Already has full data"); } } catch (Exception e) { Log.d(TAG, e.toString()); } try { if (event.getArtist().getDescription() == null) { // check if full artist data already in realm requestFullData(artistID, "Artist"); Log.d(TAG, "Requesting full artist data..."); } else { Log.d(TAG, "Already has full artist data"); } } catch (Exception e) { Log.d(TAG, e.toString()); } try { if (event.getVenue().getSw_website() == null) { // check if full venue data already in realm requestFullData(venueID, "Venue"); Log.d(TAG, "Requesting full venue data..."); } else { Log.d(TAG, "Already has full venue data"); } } catch (Exception e) { Log.d(TAG, e.toString()); } _close.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); }
public MeiziPresenter(IMeizi view) { super(view); realm = Realm.getDefaultInstance(); gankApi = RequestFactory.createApi(GankApi.class); }
public OverheadService() { realm = Realm.getDefaultInstance(); transactionRepository = new TransactionRepositoryImpl(new DiskTransactionDataStore(realm)); }