-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #396 non-purchased apps have "buy" button now, purchased and fr…
…ee apps have "download" button
- Loading branch information
Showing
19 changed files
with
292 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
app/src/main/java/com/github/yeriomin/yalpstore/SharedPreferencesCachedSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Yalp Store | ||
* Copyright (C) 2018 Sergey Yeriomin <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
package com.github.yeriomin.yalpstore; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.preference.PreferenceManager; | ||
|
||
import java.util.Collection; | ||
import java.util.HashSet; | ||
|
||
public class SharedPreferencesCachedSet extends HashSet<String> { | ||
|
||
static private final long DEFAULT_VALID_TIME = 1000*60*60*24; | ||
|
||
static private final String PREFERENCE_PREFIX = "PREFERENCE_"; | ||
static private final String _UPDATE_TIME = "_UPDATE_TIME"; | ||
static private final String _NOT_LOGGED_IN = "_NOT_LOGGED_IN"; | ||
|
||
private String name; | ||
private SharedPreferences preferences; | ||
|
||
public SharedPreferencesCachedSet(String name, Context context) { | ||
this(name, PreferenceManager.getDefaultSharedPreferences(context)); | ||
} | ||
|
||
public SharedPreferencesCachedSet(String name, SharedPreferences preferences) { | ||
this(name); | ||
setPreferences(preferences); | ||
} | ||
|
||
public SharedPreferencesCachedSet(String name) { | ||
this.name = name; | ||
} | ||
|
||
public void setPreferences(SharedPreferences preferences) { | ||
this.preferences = preferences; | ||
addAll(PreferenceUtil.getStringSet(preferences, getStorageKey())); | ||
} | ||
|
||
public boolean timeToUpdate() { | ||
return preferences.getLong(getLastUpdateTimeKey(), 0) + getValidTime() < System.currentTimeMillis(); | ||
} | ||
|
||
@Override | ||
public boolean addAll(Collection<? extends String> c) { | ||
boolean modified = super.addAll(c); | ||
if (modified) { | ||
save(); | ||
} | ||
return modified; | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
super.clear(); | ||
save(); | ||
} | ||
|
||
public void save() { | ||
PreferenceUtil.putStringSet(preferences, getStorageKey(), this); | ||
preferences.edit().putLong(getLastUpdateTimeKey(), System.currentTimeMillis()).commit(); | ||
} | ||
|
||
protected String getStorageKey() { | ||
return PREFERENCE_PREFIX + name + (preferences.getBoolean(PlayStoreApiAuthenticator.PREFERENCE_APP_PROVIDED_EMAIL, true) ? _NOT_LOGGED_IN : preferences.getString(PlayStoreApiAuthenticator.PREFERENCE_EMAIL, "")); | ||
} | ||
|
||
protected String getLastUpdateTimeKey() { | ||
return getStorageKey() + _UPDATE_TIME; | ||
} | ||
|
||
protected long getValidTime() { | ||
return DEFAULT_VALID_TIME; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
app/src/main/java/com/github/yeriomin/yalpstore/fragment/details/ButtonBuy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Yalp Store | ||
* Copyright (C) 2018 Sergey Yeriomin <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
package com.github.yeriomin.yalpstore.fragment.details; | ||
|
||
import android.view.View; | ||
|
||
import com.github.yeriomin.yalpstore.R; | ||
import com.github.yeriomin.yalpstore.YalpStoreActivity; | ||
import com.github.yeriomin.yalpstore.YalpStoreApplication; | ||
import com.github.yeriomin.yalpstore.model.App; | ||
import com.github.yeriomin.yalpstore.view.PurchaseDialogBuilder; | ||
import com.github.yeriomin.yalpstore.view.UriOnClickListener; | ||
|
||
class ButtonBuy extends Button { | ||
|
||
public ButtonBuy(YalpStoreActivity activity, App app) { | ||
super(activity, app); | ||
} | ||
|
||
@Override | ||
protected View getButton() { | ||
return activity.findViewById(R.id.buy); | ||
} | ||
|
||
@Override | ||
protected boolean shouldBeVisible() { | ||
return !YalpStoreApplication.purchasedPackageNames.contains(app.getPackageName()) && !app.isInstalled() && !app.isFree(); | ||
} | ||
|
||
@Override | ||
public void draw() { | ||
super.draw(); | ||
android.widget.Button button = (android.widget.Button) getButton(); | ||
if (null != button) { | ||
button.setText(app.getPrice()); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onButtonClick(View v) { | ||
new UriOnClickListener(activity, PurchaseDialogBuilder.URL_PURCHASE + app.getPackageName()).onClick(v); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.