private Notifications(Context context) { this.applicationContext = context.getApplicationContext(); this.preferences = Preferences.getInstance(applicationContext); this.gcm = Gcm.getInstance(applicationContext); this.notificationIds = new HashMap<>(); this.notificationIdCount = 0; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.conversations); gcm = Gcm.getInstance(getApplicationContext()); billing = Billing.getInstance(getApplicationContext()); database = Database.getInstance(getApplicationContext()); preferences = Preferences.getInstance(getApplicationContext()); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); ViewCompat.setElevation(toolbar, getResources().getDimension(R.dimen.toolbar_elevation)); setSupportActionBar(toolbar); LinearLayoutManager layoutManager = new LinearLayoutManager(this); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); adapter = new ConversationsRecyclerViewAdapter(this, layoutManager); recyclerView = (RecyclerView) findViewById(R.id.list); recyclerView.setHasFixedSize(true); recyclerView.setLayoutManager(layoutManager); recyclerView.setAdapter(adapter); actionMode = null; actionModeEnabled = false; SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout); swipeRefreshLayout.setOnRefreshListener( new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { preFullUpdate(); } }); swipeRefreshLayout.setColorSchemeResources(R.color.accent); ImageButton button = (ImageButton) findViewById(R.id.new_button); ViewCompat.setElevation(button, getResources().getDimension(R.dimen.fab_elevation)); button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (!preferences.getEmail().equals("") && !preferences.getPassword().equals("") && !preferences.getDid().equals("")) { Intent intent = new Intent(conversationsActivity, NewConversationActivity.class); startActivity(intent); } } }); SynchronizationIntervalReceiver.setupSynchronizationInterval(getApplicationContext()); }
/** * Initiates a full update of the message database. This update follows all synchronization rules * set in the application's settings. */ public void preFullUpdate() { adapter.refresh(); gcm.registerForGcm(conversationsActivity, false, false); database.synchronize(false, true, conversationsActivity); }