@Override protected void beforeActivityLaunched() { super.beforeActivityLaunched(); FirebaseDatabase database = mock(FirebaseDatabase.class); DatabaseReference reference = mock(DatabaseReference.class); Query query = mock(Query.class); when(database.getReference()).thenReturn(reference); when(reference.child(null)).thenReturn(reference); when(reference.child(any(String.class))).thenReturn(reference); when(reference.orderByChild(any(String.class))).thenReturn(query); FirebaseProvider.setFirebaseDatabase(database); }
/** Inits firebase */ public void initFirebase() { // Set local persistence if (!FirebaseApp.getApps(this).isEmpty()) { FirebaseDatabase.getInstance().setPersistenceEnabled(true); } }
public DetailsPresenter(DetailsView detailsView, BaseActivity activity) { this.detailsView = detailsView; this.activity = activity; this.database = FirebaseDatabase.getInstance().getReference(FirebaseLink.forNotes()); this.storage = FirebaseStorage.getInstance().getReferenceFromUrl(Secrets.FIREBASE_STORAGE); this.password = activity.getAuthHandler().getCredentials().getId(); this.filesDir = activity.getFilesDir(); }
@Override public void onCreate() { super.onCreate(); mInstance = this; preferences = getSharedPreferences("POLICY_CHECK", Context.MODE_PRIVATE); // Firebase.setAndroidContext(this); /* Enable disk persistence */ if (!FirebaseApp.getApps(this).isEmpty()) { FirebaseDatabase.getInstance().setPersistenceEnabled(true); } }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); View root = inflater.inflate(R.layout.fragment_site_list, container, false); mDatabase = FirebaseDatabase.getInstance().getReference(); mRecyclerView = (RecyclerView) root.findViewById(R.id.site_list); mRecyclerView.setHasFixedSize(true); return root; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_mojo_menu); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBar supportActionBar = getSupportActionBar(); if (supportActionBar != null) { supportActionBar.setTitle(R.string.nav_menu_title); } navigationDrawer = (DrawerLayout) findViewById(R.id.mojo_menu_drawer_layout); navigationDrawerToggle = new ActionBarDrawerToggle( this, navigationDrawer, toolbar, R.string.action_open_navigation_drawer, R.string.action_close_navigation_drawer) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (navigationView.getMenu().findItem(R.id.nav_orders).isChecked()) { ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation( MojoMenuActivity.this, toolbar, getString(R.string.toolbar_transition)); MojoOrderActivity.start( MojoMenuActivity.this, orderItemList, optionsCompat.toBundle()); } else if (navigationView.getMenu().findItem(R.id.nav_settings).isChecked()) { SettingsActivity.start(MojoMenuActivity.this); } navigationView.setCheckedItem(R.id.nav_menu); } }; navigationDrawer.addDrawerListener(navigationDrawerToggle); navigationView = (NavigationView) findViewById(R.id.mojo_menu_nav_view); navigationView.setCheckedItem(R.id.nav_menu); navigationView.setNavigationItemSelectedListener(this); goToCartButton = (Button) findViewById(R.id.bottom_action_button); goToCartButton.setOnClickListener(this); tabLayout = (TabLayout) findViewById(R.id.mojo_menu_tab_layout); viewPager = (ViewPager) findViewById(R.id.mojo_menu_view_pager); baseReference = FirebaseDatabase.getInstance().getReference().child("data"); mojoDataChildEventListener = new MojoDataChildEventListener(); if (savedInstanceState != null) { mojoData = savedInstanceState.getParcelable(EXTRA_MOJO_DATA); orderItemList = savedInstanceState.getParcelableArrayList(EXTRA_ORDER_ITEM_LIST); updateTabLayoutAndViewPager(); updateGoToCartButton(); } else { mojoData = new MojoData(); orderItemList = new ArrayList<>(); showLoadingDialog(); baseReference.addListenerForSingleValueEvent( new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { dismissLoadingDialog(); if (dataSnapshot != null && dataSnapshot.exists()) { ArrayList<MojoMenu> mojoMenuList = new ArrayList<>(); ArrayList<Topping> toppingList = new ArrayList<>(); ArrayList<String> availableZipList = new ArrayList<>(); Map<String, Map<String, Object>> mojoDataMap = (Map<String, Map<String, Object>>) dataSnapshot.getValue(); Map<String, Object> toppingDataMap = mojoDataMap.get("topping"); for (Object toppingData : toppingDataMap.values()) { toppingList.add(new Topping((Map<String, Object>) toppingData)); } Map<String, Object> menuDataMap = mojoDataMap.get("menu"); for (Object menuData : menuDataMap.values()) { mojoMenuList.add(new MojoMenu((Map<String, Object>) menuData)); } availableZipList.addAll((List<String>) mojoDataMap.get("zip")); mojoData.setMojoMenuList(mojoMenuList); mojoData.setToppingList(toppingList); mojoData.setAvailableZipList(availableZipList); updateTabLayoutAndViewPager(); } } @Override public void onCancelled(DatabaseError databaseError) { dismissLoadingDialog(); Log.e("findme", "Load menu data failed: " + databaseError.getMessage()); } }); } }
private void setupFirebase() { FirebaseDatabase.getInstance().setPersistenceEnabled(true); }
public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY); HashMap<Date, ArrayList<HashMap<String, Object>>> resultado = new HashMap<Date, ArrayList<HashMap<String, Object>>>(); List<TimeLinePopUp> listaPopUps = new ArrayList<TimeLinePopUp>(); PortletPreferences prefs = renderRequest.getPreferences(); String showInMain = prefs.getValue("showInMain", "true"); String showItems = prefs.getValue("showItems", "true"); String showAlerts = prefs.getValue("showAlerts", "true"); // ********************* // 1) Sites de LIFERAY // ********************* List<Group> offices = new ArrayList<Group>(); // Si el portlet se muestra en la pagina ppal, recorremos todas las oficianas a partir de un // sitio padre leido desde properties if (showInMain.equals("true")) { String mainSiteGroupId = com.liferay.util.portlet.PortletProps.get("lfvo.main.site.group.id"); if (mainSiteGroupId != null && !"".equals(mainSiteGroupId)) { try { offices = GroupLocalServiceUtil.getGroups( themeDisplay.getCompanyId(), Long.parseLong(mainSiteGroupId), true); } catch (NumberFormatException e) { e.printStackTrace(); offices = GroupLocalServiceUtil.getGroups(themeDisplay.getCompanyId(), 0, true); } } else { offices = GroupLocalServiceUtil.getGroups(themeDisplay.getCompanyId(), 0, true); } // Si el portlet no se muestra en la pagina ppal, cogemos la oficina del sitio } else { offices.add(themeDisplay.getScopeGroup()); } // ********************* // 2) Sites de FIREBASE // ********************* HashMap<String, Object> officesMap = new HashMap<String, Object>(); try { DatabaseReference ref = FirebaseDatabase.getInstance().getReference("/offices/"); Firebase firebase = new Firebase(ref.toString()); FirebaseResponse response = firebase.get(); officesMap = (HashMap<String, Object>) response.getBody(); } catch (FirebaseException e2) { e2.printStackTrace(); } if (officesMap != null) { for (Group office : offices) { HashMap<String, Object> officeBD = (HashMap<String, Object>) officesMap.get( String.valueOf(office.getGroupId())); // Site Firebase <> Site Liferay if (officeBD != null) { try { List<Item> items = ItemLocalServiceUtil.getItems(office.getGroupId(), -1, -1); for (Item item : items) { // Si s�lo mostramos ITEMS y no ALERTS... if (showItems.equals("true") & showAlerts.equals("false")) { if (!"".equals(item.getType()) & !item.getType() .equals("office")) { // Si tiene tipo, pero no es 'office' descartamos continue; } } // Si s�lo mostramos ALERTS y no ITEMS... if (showItems.equals("false") & showAlerts.equals("true")) { if ("".equals(item.getType()) || item.getType() .equals("office")) { // Si es vacio o es 'office' descartamos continue; } } // Si no mostramos nada... if (showItems.equals("false") & showAlerts.equals("false")) { continue; } HashMap<String, Object> miItem = new HashMap<String, Object>(); // Creamos una fecha con formato simple Date createDate = item.getCreateDate(); String fechaFormat = ""; String fechaFormatEus = ""; SimpleDateFormat dt1 = new SimpleDateFormat("dd/MM/yyyy"); SimpleDateFormat dt2 = new SimpleDateFormat("yyyy/MM/dd"); if (createDate != null) { fechaFormat = dt1.format(item.getCreateDate()); fechaFormatEus = dt2.format(item.getCreateDate()); } else { fechaFormat = dt1.format(item.getModifiedDate()); fechaFormatEus = dt2.format(item.getModifiedDate()); } // Quitamos la hora y minutos de la fecha original SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); Date b = new Date(); try { b = formatter.parse(fechaFormat); } catch (ParseException e) { } // PopUp - Mapa Street TimeLinePopUp miPopUp = new TimeLinePopUp(); miPopUp.setDate_es(fechaFormat); miPopUp.setDate_eu(fechaFormatEus); miPopUp.setName(item.getName()); miPopUp.setImage(this.obtenerImagenItem(item.getItemId())); miPopUp.setLat(String.valueOf(item.getLat())); miPopUp.setLng(String.valueOf(item.getLng())); listaPopUps.add(miPopUp); // HashMaps - Timeline miItem.put("image", this.obtenerImagenItem(item.getItemId())); miItem.put("name", item.getName()); miItem.put("desc", item.getDescription()); miItem.put("lat", item.getLat()); miItem.put("lng", item.getLng()); miItem.put("type", item.getType()); if (resultado.get(b) == null) { resultado.put(b, new ArrayList<HashMap<String, Object>>()); } resultado.get(b).add(miItem); } } catch (PortalException e) { e.printStackTrace(); } } } } // Lista de PopUps Type listType = new TypeToken<List<TimeLinePopUp>>() {}.getType(); Gson gson = new Gson(); String json = gson.toJson(listaPopUps, listType); renderRequest.setAttribute("popUps", json); // En vez de ordenar el hashmap, ordenamos las keys ArrayList<Date> miArray = new ArrayList<Date>(); for (Date date : resultado.keySet()) { miArray.add(date); } Collections.sort(miArray); renderRequest.setAttribute("resultado", resultado); renderRequest.setAttribute("orderedKeys", miArray); super.doView(renderRequest, renderResponse); }
public class EduCover extends AppCompatActivity implements View.OnClickListener, RadioGroup.OnCheckedChangeListener, AdapterView.OnItemSelectedListener { private static DatabaseReference sref = FirebaseDatabase.getInstance().getReference().child("companies"); Button button; EditText name_assured; EditText age_next; EditText name_child; EditText policy_term; EditText sum; EditText premium; EditText target; EditText age_child; String name; String age; String child; String policy; String sum_; String prem; String targ; String age_c; boolean a = false; boolean b = false; boolean c = false; boolean d = false; boolean e = false; boolean f = false; Spinner spinner; ArrayAdapter<CharSequence> adapter2; EditText ag; LinearLayout agent; String intermediary; MotorObject motor; MedicalObject medical; TravelObject travel; CorporateObject corporate; EduObject edu; Covers ci; private RadioGroup radio1; private RadioGroup radio2; private RadioGroup radio3; private RadioGroup radio4; private RadioGroup radio5; private RadioGroup radio6; private boolean inter = false; private String ag_; private boolean zzz = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_edu_insurance); Toolbar toolbar = (Toolbar) findViewById(R.id.medical_insurance_toolbar); button = (Button) findViewById(R.id.eduNext); setSupportActionBar(toolbar); name_assured = (EditText) findViewById(R.id.assured_name_txt); age_next = (EditText) findViewById(R.id.Age_Next_Birthday_txt); name_child = (EditText) findViewById(R.id.Name_of_Child_txt); policy_term = (EditText) findViewById(R.id.Policy_Term_txt); // sum = (EditText) findViewById(R.id.Sum_Assured_txt); premium = (EditText) findViewById(R.id.Premium_txt); // target = (EditText) findViewById(R.id.Target_Amount_txt); age_child = (EditText) findViewById(R.id.Age_of_Child_txt); radio1 = (RadioGroup) findViewById(R.id.TotalPermanent); radio2 = (RadioGroup) findViewById(R.id.WaiverofPre); radio3 = (RadioGroup) findViewById(R.id.ChildAccident); radio4 = (RadioGroup) findViewById(R.id.AdultAccident); radio5 = (RadioGroup) findViewById(R.id.LastExpenseLife); radio6 = (RadioGroup) findViewById(R.id.LastExpense); spinner = (Spinner) findViewById(R.id.intermediary_direct); adapter2 = ArrayAdapter.createFromResource( this, R.array.inter_direct, android.R.layout.simple_spinner_item); adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); agent = (LinearLayout) findViewById(R.id.agent); spinner.setAdapter(adapter2); spinner.setOnItemSelectedListener(this); ag = (EditText) findViewById(R.id.agent_email); button.setOnClickListener(this); radio1.setOnCheckedChangeListener(this); radio2.setOnCheckedChangeListener(this); radio3.setOnCheckedChangeListener(this); radio4.setOnCheckedChangeListener(this); radio5.setOnCheckedChangeListener(this); radio6.setOnCheckedChangeListener(this); loadCompaniess("motor"); loadCompaniess("edu"); loadCompaniess("corporate"); loadCompaniess("medical"); loadCompaniess("travel"); } public void loadCompaniess(final String s) { final StringBuilder bn = new StringBuilder(); com.google.firebase.database.Query queryRef; queryRef = sref.orderByChild("offered").equalTo("YES"); sref.addValueEventListener( new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { for (DataSnapshot snapshot : dataSnapshot.getChildren()) { ci = snapshot.getValue(Covers.class); motor = ci.getMotor(); medical = ci.getMedical(); travel = ci.getTravel(); edu = ci.getEdu(); corporate = ci.getCorporate(); switch (s) { case "motor": zzz = true; zzz = false; break; case "edu": zzz = true; zzz = false; break; case "medical": zzz = true; zzz = false; break; case "travel": zzz = true; zzz = false; break; case "corporate": zzz = true; zzz = false; break; } } } @Override public void onCancelled(DatabaseError databaseError) {} }); } @Override public boolean onCreateOptionsMenu(Menu menu) { return super.onCreateOptionsMenu(menu); } @Override public void onBackPressed() { super.onBackPressed(); overridePendingTransition(R.anim.pause_open, R.anim.pause_close); } @Override public boolean onOptionsItemSelected(MenuItem item) { return super.onOptionsItemSelected(item); } @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.TotalPermanentDisabilty_text_no: a = false; break; case R.id.TotalPermanentDisabilty_text_yes: a = true; break; case R.id.WaiverofPremium_no: b = false; break; case R.id.WaiverofPremium_yes: b = true; break; case R.id.ChildAccidentHospitalizationRider_no: c = false; break; case R.id.ChildAccidentHospitalizationRider_yes: c = true; break; case R.id.AdultAccidentHospitalizationRider_no: d = false; break; case R.id.AdultAccidentHospitalizationRider_yes: d = true; break; case R.id.LastExpenseLifeAssured_no: e = false; break; case R.id.LastExpenseLifeAssured_yes: e = true; break; case R.id.LastExpenseBeneficiarychild_no: f = false; break; case R.id.LastExpenseBeneficiarychild_yes: f = true; break; } } @Override public void onClick(View v) { int i = 0; Bundle bundle = new Bundle(); name = name_assured.getText().toString().trim(); age = age_next.getText().toString().trim(); age_c = age_child.getText().toString().trim(); child = name_child.getText().toString().trim(); policy = policy_term.getText().toString().trim(); // sum_ = sum.getText().toString().trim(); prem = premium.getText().toString().trim(); // targ = target.getText().toString().trim(); ag_ = ag.getText().toString(); if (v.getId() == R.id.eduNext) { /*if (!sum_.isEmpty()) { i +=1; }*/ if (!prem.isEmpty()) { i += 1; } /*if (!targ.isEmpty()) { i +=1; }*/ if (!name.isEmpty() && !age.isEmpty() && !age_c.isEmpty() && !child.isEmpty() && !policy.isEmpty() && !prem.isEmpty() && inter) { Intent intent = new Intent(EduCover.this, GeneralQuote.class); bundle.putString("name", name); bundle.putString("cover", "edu"); bundle.putString("age", age); bundle.putString("age_c", age_c); bundle.putString("child", child); bundle.putString("policy", policy); bundle.putString("total", (a) ? "included" : "none"); bundle.putString("waiver", (b) ? "included" : "none"); bundle.putString("childAcc", (c) ? "included" : "none"); bundle.putString("adult", (d) ? "included" : "none"); bundle.putString("life", (e) ? "included" : "none"); bundle.putString("beneficiary", (f) ? "included" : "none"); bundle.putString("agentt", (!ag_.isEmpty()) ? ag_ : "Direct"); // if (i == 1) { // bundle.putString("sum", sum_); bundle.putString("premium", prem); // bundle.putString("target", targ); intent.putExtras(bundle); startActivity(intent); overridePendingTransition(R.anim.open_transition, R.anim.close_transition); /*} else { Toast.makeText(this, "You must fill only one of the optional fields", Toast.LENGTH_LONG).show(); }*/ } else { Toast.makeText(this, "You must fill all the compulsory fields", Toast.LENGTH_LONG).show(); } } } @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { switch (parent.getId()) { case R.id.intermediary_direct: if (!parent.getItemAtPosition(position).toString().equalsIgnoreCase("Select a category")) { inter = true; intermediary = parent.getItemAtPosition(position).toString(); if (intermediary.equalsIgnoreCase("Agent/Broker")) { agent.setVisibility(View.VISIBLE); } else { ag.setText(""); agent.setVisibility(View.GONE); } } break; } } @Override public void onNothingSelected(AdapterView<?> parent) {} }