Пример #1
0
  @Override
  @Nullable
  public Entry get(@Nonnull Key key) {
    if (cache != null) {
      synchronized (this) {
        final Entry entry = cache.get(key);
        if (entry == null) {
          Billing.debug(TAG, "Key=" + key + " is not in the cache");
          return null;
        }
        final long now = currentTimeMillis();
        if (now >= entry.expiresAt) {
          Billing.debug(
              TAG,
              "Key="
                  + key
                  + " is in the cache but was expired at "
                  + entry.expiresAt
                  + ", now is "
                  + now);
          cache.remove(key);
          return null;
        }
        Billing.debug(TAG, "Key=" + key + " is in the cache");
        return entry;
      }
    }

    return null;
  }
Пример #2
0
 public void putIfNotExist(@Nonnull Key key, @Nonnull Entry entry) {
   if (cache != null) {
     synchronized (this) {
       if (cache.get(key) == null) {
         Billing.debug(TAG, "Adding entry with key=" + key + " to the cache");
         cache.put(key, entry);
       } else {
         Billing.debug(TAG, "Entry with key=" + key + " is already in the cache, won't add");
       }
     }
   }
 }
Пример #3
0
 @Override
 public void put(@Nonnull Key key, @Nonnull Entry entry) {
   if (cache != null) {
     synchronized (this) {
       Billing.debug(TAG, "Adding entry with key=" + key + " to the cache");
       cache.put(key, entry);
     }
   }
 }
Пример #4
0
 @Override
 public void clear() {
   if (cache != null) {
     synchronized (this) {
       Billing.debug(TAG, "Clearing the cache");
       cache.clear();
     }
   }
 }
Пример #5
0
 @Override
 public void removeAll(int type) {
   if (cache != null) {
     synchronized (this) {
       Billing.debug(TAG, "Removing all entries with type=" + type + " from the cache");
       cache.removeAll(type);
     }
   }
 }
Пример #6
0
 @Override
 public void remove(@Nonnull Key key) {
   if (cache != null) {
     synchronized (this) {
       Billing.debug(TAG, "Removing entry with key=" + key + " from the cache");
       cache.remove(key);
     }
   }
 }
Пример #7
0
 @Override
 public void init() {
   if (cache != null) {
     synchronized (this) {
       Billing.debug(TAG, "Initializing cache");
       cache.init();
     }
   }
 }
  @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());
  }
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (requestCode == 1001 && resultCode == RESULT_OK) {
     try {
       String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
       JSONObject json = new JSONObject(purchaseData);
       String token = json.getString("purchaseToken");
       billing.postDonation(token, this);
     } catch (Exception ignored) {
       // Do nothing.
     }
   }
 }
 static void insertPurchases(
     @Nonnull Billing billing, @Nonnull String product, @Nonnull List<Purchase> purchases)
     throws RemoteException {
   final Bundle bundle = newBundle(OK);
   final ArrayList<String> list = new ArrayList<String>();
   for (Purchase purchase : purchases) {
     list.add(purchase.toJson());
   }
   bundle.putStringArrayList(Purchases.BUNDLE_DATA_LIST, list);
   final IInAppBillingService service = ((TestServiceConnector) billing.getConnector()).service;
   when(service.getPurchases(anyInt(), anyString(), eq(product), isNull(String.class)))
       .thenReturn(bundle);
 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case R.id.preferences_button:
       Intent preferencesIntent = new Intent(this, PreferencesActivity.class);
       startActivity(preferencesIntent);
       return true;
     case R.id.help_button:
       Intent helpIntent = new Intent(this, HelpActivity.class);
       startActivity(helpIntent);
       return true;
     case R.id.credits_button:
       Intent creditsIntent = new Intent(this, CreditsActivity.class);
       startActivity(creditsIntent);
       return true;
     case R.id.donate_button:
       billing.preDonation(this);
     default:
       return super.onOptionsItemSelected(item);
   }
 }
 @Nullable
 @Override
 public Cache getCache() {
   return Billing.newCache();
 }
 @Override
 public void onCreate() {
   super.onCreate();
   billing.connect();
 }