Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 52 additions & 4 deletions res/layout/main_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@
style="@style/MainTableText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/main_app_rating"
android:layout_alignRight="@+id/main_app_icon_frame"
android:layout_below="@+id/main_app_ratingbar"
android:gravity="right"
android:maxLines="1"
android:minWidth="65dp"
android:paddingBottom="2dp"
android:paddingRight="5dp"
android:paddingTop="2dp" >
android:paddingTop="2dp">
</TextView>

<TextView
Expand All @@ -110,7 +110,7 @@
android:layout_alignParentRight="true"
android:paddingRight="50dp" />
</RelativeLayout>

<RelativeLayout
android:id="@+id/main_app_download_frame"
android:layout_width="fill_parent"
Expand Down Expand Up @@ -197,12 +197,59 @@
android:layout_alignParentRight="true"
android:paddingRight="55dp" />
</RelativeLayout>

<RelativeLayout
android:id="@+id/main_app_revenue_frame"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/main_app_download_frame"
android:background="@drawable/row_background_inner_borderless"
android:paddingLeft="10dp"
android:paddingRight="10dp" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:paddingRight="5dp"
android:scaleType="fitXY"
android:src="@drawable/icon_more" />

<View
android:id="@+id/main_app_spacer_revenue"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="@drawable/row_dash" />

<TextView
android:id="@+id/main_app_revenue_total_text"
style="@style/MainTableText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/main_app_spacer_revenue"
android:gravity="right"
android:minWidth="70dp"
android:paddingLeft="10dp"
android:paddingRight="5dp"
android:paddingTop="3dp"
android:paddingBottom="3dp" />

<TextView
android:id="@+id/main_app_admob_revenue_total_label"
style="@style/MainTableText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/main_app_revenue_total_text"
android:layout_toRightOf="@+id/main_app_revenue_total_text"
android:text="@string/revenue_total" />
</RelativeLayout>

<RelativeLayout
android:id="@+id/main_app_admob_frame"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/main_app_download_frame"
android:layout_below="@+id/main_app_revenue_frame"
android:background="@drawable/row_background_inner_borderless"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
Expand Down Expand Up @@ -241,6 +288,7 @@
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/main_app_admob_revenue"
android:layout_toRightOf="@+id/main_app_admob_revenue"
android:paddingBottom="3dp"
android:text="@string/admob_revenue" />

<TextView
Expand Down
5 changes: 5 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,9 @@
<string name="appinfo_playstore_button">View in the Play Store</string>
<string name="appinfo_addlink_button">Add a link</string>
<string name="appinfo_app_links">App links</string>

<string name="revenue_total">Revenue total (1/7d)</string>
<string name="revenue_last_day">Revenue last day</string>
<string name="revenue_last_7days">Revenue last 7 days</string>
<string name="revenue_last_30days">Revenue last 30 days</string>
</resources>
188 changes: 132 additions & 56 deletions src/com/github/andlyticsproject/ContentAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
import com.github.andlyticsproject.db.AppInfoTable;
import com.github.andlyticsproject.db.AppStatsTable;
import com.github.andlyticsproject.db.CommentsTable;
import com.github.andlyticsproject.db.RevenueSummaryTable;
import com.github.andlyticsproject.model.Admob;
import com.github.andlyticsproject.model.AdmobList;
import com.github.andlyticsproject.model.AppInfo;
import com.github.andlyticsproject.model.AppStats;
import com.github.andlyticsproject.model.AppStatsList;
import com.github.andlyticsproject.model.Comment;
import com.github.andlyticsproject.model.RevenueSummary;
import com.github.andlyticsproject.util.Utils;

public class ContentAdapter {
Expand Down Expand Up @@ -280,39 +282,42 @@ public AppStatsDiff insertOrUpdateStats(AppInfo appInfo) {
return createAppStatsDiff(downloadInfo, previousStats, appInfo);
}

public void insertOrUpdateAppStats(AppStats downloadInfo, String packageName) {
public void insertOrUpdateAppStats(AppStats appStats, String packageName) {

ContentValues values = new ContentValues();

values.put(AppStatsTable.KEY_STATS_REQUESTDATE,
Utils.formatDbDate(downloadInfo.getRequestDate()));
Utils.formatDbDate(appStats.getRequestDate()));
values.put(AppStatsTable.KEY_STATS_PACKAGENAME, packageName);
values.put(AppStatsTable.KEY_STATS_DOWNLOADS, downloadInfo.getTotalDownloads());
values.put(AppStatsTable.KEY_STATS_INSTALLS, downloadInfo.getActiveInstalls());
values.put(AppStatsTable.KEY_STATS_COMMENTS, downloadInfo.getNumberOfComments());
values.put(AppStatsTable.KEY_STATS_DOWNLOADS, appStats.getTotalDownloads());
values.put(AppStatsTable.KEY_STATS_INSTALLS, appStats.getActiveInstalls());
values.put(AppStatsTable.KEY_STATS_COMMENTS, appStats.getNumberOfComments());
values.put(AppStatsTable.KEY_STATS_MARKETERANKING, -1);
values.put(AppStatsTable.KEY_STATS_CATEGORYRANKING, -1);

if (downloadInfo.getRating5() != null) {
values.put(AppStatsTable.KEY_STATS_5STARS, downloadInfo.getRating5());
if (appStats.getRating5() != null) {
values.put(AppStatsTable.KEY_STATS_5STARS, appStats.getRating5());
}
if (downloadInfo.getRating4() != null) {
values.put(AppStatsTable.KEY_STATS_4STARS, downloadInfo.getRating4());
if (appStats.getRating4() != null) {
values.put(AppStatsTable.KEY_STATS_4STARS, appStats.getRating4());
}
if (downloadInfo.getRating3() != null) {
values.put(AppStatsTable.KEY_STATS_3STARS, downloadInfo.getRating3());
if (appStats.getRating3() != null) {
values.put(AppStatsTable.KEY_STATS_3STARS, appStats.getRating3());
}
if (downloadInfo.getRating2() != null) {
values.put(AppStatsTable.KEY_STATS_2STARS, downloadInfo.getRating2());
if (appStats.getRating2() != null) {
values.put(AppStatsTable.KEY_STATS_2STARS, appStats.getRating2());
}
if (downloadInfo.getRating1() != null) {
values.put(AppStatsTable.KEY_STATS_1STARS, downloadInfo.getRating1());
if (appStats.getRating1() != null) {
values.put(AppStatsTable.KEY_STATS_1STARS, appStats.getRating1());
}
if (downloadInfo.getVersionCode() != null) {
values.put(AppStatsTable.KEY_STATS_VERSIONCODE, downloadInfo.getVersionCode());
if (appStats.getVersionCode() != null) {
values.put(AppStatsTable.KEY_STATS_VERSIONCODE, appStats.getVersionCode());
}
if (downloadInfo.getNumberOfErrors() != null) {
values.put(AppStatsTable.KEY_STATS_NUM_ERRORS, downloadInfo.getNumberOfErrors());
if (appStats.getNumberOfErrors() != null) {
values.put(AppStatsTable.KEY_STATS_NUM_ERRORS, appStats.getNumberOfErrors());
}
if (appStats.getTotalRevenue() != null) {
values.put(AppStatsTable.KEY_STATS_TOTAL_REVENUE, appStats.getTotalRevenue());
}

context.getContentResolver().insert(AppStatsTable.CONTENT_URI, values);
Expand Down Expand Up @@ -377,6 +382,28 @@ private void insertOrUpdateApp(AppInfo appInfo) {
long id = Long.parseLong(uri.getPathSegments().get(1));
appInfo.setId(id);

// XXX here?
RevenueSummary revenue = appInfo.getTotalRevenueSummary();
if (revenue != null) {
ContentValues values = new ContentValues();
values.put(RevenueSummaryTable.TYPE, revenue.getType().ordinal());
values.put(RevenueSummaryTable.CURRENCY, revenue.getCurrency());
values.put(RevenueSummaryTable.LAST_DAY_TOTAL, revenue.getLastDay());
values.put(RevenueSummaryTable.LAST_7DAYS_TOTAL, revenue.getLast7Days());
values.put(RevenueSummaryTable.LAST_30DAYS_TOTAL, revenue.getLast30Days());
values.put(RevenueSummaryTable.APPINFO_ID, appInfo.getId());

if (revenue.getId() == null) {
uri = context.getContentResolver().insert(RevenueSummaryTable.CONTENT_URI, values);
id = Long.parseLong(uri.getPathSegments().get(1));
revenue.setId(id);
} else {
context.getContentResolver().update(RevenueSummaryTable.CONTENT_URI, values,
RevenueSummaryTable.APPINFO_ID + " = ?",
new String[] { Long.toString(revenue.getId()) });
}
}

backupManager.dataChanged();
}

Expand Down Expand Up @@ -502,6 +529,10 @@ public List<AppInfo> getAllAppsLatestStats(String account) {
stats.init();

appInfo.setLatestStats(stats);

//
RevenueSummary revenueSummary = getRevenueSummaryForApp(appInfo);
appInfo.setTotalRevenueSummary(revenueSummary);
}

return appInfos;
Expand Down Expand Up @@ -882,52 +913,97 @@ public AppStatsList getStatsForApp(String packageName, Timeframe currentTimeFram

public AppStats getLatestForApp(String packageName) {

AppStats info = null;
AppStats stats = null;
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(
AppStatsTable.CONTENT_URI,
new String[] { AppStatsTable.KEY_ROWID, AppStatsTable.KEY_STATS_PACKAGENAME,
AppStatsTable.KEY_STATS_DOWNLOADS, AppStatsTable.KEY_STATS_VERSIONCODE,
AppStatsTable.KEY_STATS_INSTALLS, AppStatsTable.KEY_STATS_COMMENTS,
AppStatsTable.KEY_STATS_MARKETERANKING,
AppStatsTable.KEY_STATS_CATEGORYRANKING,
AppStatsTable.KEY_STATS_5STARS, AppStatsTable.KEY_STATS_4STARS,
AppStatsTable.KEY_STATS_3STARS, AppStatsTable.KEY_STATS_2STARS,
AppStatsTable.KEY_STATS_1STARS, AppStatsTable.KEY_STATS_REQUESTDATE,
AppStatsTable.KEY_STATS_TOTAL_REVENUE },
AppStatsTable.KEY_STATS_PACKAGENAME + " = ?", new String[] { packageName },
AppStatsTable.KEY_STATS_REQUESTDATE + " desc limit 1");

Cursor cursor = context.getContentResolver().query(
AppStatsTable.CONTENT_URI,
new String[] { AppStatsTable.KEY_ROWID, AppStatsTable.KEY_STATS_PACKAGENAME,
AppStatsTable.KEY_STATS_DOWNLOADS, AppStatsTable.KEY_STATS_VERSIONCODE,
AppStatsTable.KEY_STATS_INSTALLS, AppStatsTable.KEY_STATS_COMMENTS,
AppStatsTable.KEY_STATS_MARKETERANKING,
AppStatsTable.KEY_STATS_CATEGORYRANKING, AppStatsTable.KEY_STATS_5STARS,
AppStatsTable.KEY_STATS_4STARS, AppStatsTable.KEY_STATS_3STARS,
AppStatsTable.KEY_STATS_2STARS, AppStatsTable.KEY_STATS_1STARS,
AppStatsTable.KEY_STATS_REQUESTDATE },
AppStatsTable.KEY_STATS_PACKAGENAME + "='" + packageName + "'", null,
AppStatsTable.KEY_STATS_REQUESTDATE + " desc limit 1");
if (cursor.moveToFirst()) {

if (cursor.moveToFirst()) {
do {
stats = new AppStats();
stats.setActiveInstalls(cursor.getInt(cursor
.getColumnIndex(AppStatsTable.KEY_STATS_INSTALLS)));
stats.setTotalDownloads(cursor.getInt(cursor
.getColumnIndex(AppStatsTable.KEY_STATS_DOWNLOADS)));
stats.setRequestDate(Utils.parseDbDate(cursor.getString(cursor
.getColumnIndex(AppStatsTable.KEY_STATS_REQUESTDATE))));
stats.setNumberOfComments(cursor.getInt(cursor
.getColumnIndex(AppStatsTable.KEY_STATS_COMMENTS)));
stats.setVersionCode(cursor.getInt(cursor
.getColumnIndex(AppStatsTable.KEY_STATS_VERSIONCODE)));

stats.setRating(
cursor.getInt(cursor.getColumnIndex(AppStatsTable.KEY_STATS_1STARS)),
cursor.getInt(cursor.getColumnIndex(AppStatsTable.KEY_STATS_2STARS)),
cursor.getInt(cursor.getColumnIndex(AppStatsTable.KEY_STATS_3STARS)),
cursor.getInt(cursor.getColumnIndex(AppStatsTable.KEY_STATS_4STARS)),
cursor.getInt(cursor.getColumnIndex(AppStatsTable.KEY_STATS_5STARS)));
int idx = cursor.getColumnIndex(AppStatsTable.KEY_STATS_TOTAL_REVENUE);
if (!cursor.isNull(idx)) {
stats.setTotalRevenue(cursor.getDouble(idx));
}

do {
info = new AppStats();
info.setActiveInstalls(cursor.getInt(cursor
.getColumnIndex(AppStatsTable.KEY_STATS_INSTALLS)));
info.setTotalDownloads(cursor.getInt(cursor
.getColumnIndex(AppStatsTable.KEY_STATS_DOWNLOADS)));
info.setRequestDate(Utils.parseDbDate(cursor.getString(cursor
.getColumnIndex(AppStatsTable.KEY_STATS_REQUESTDATE))));
info.setNumberOfComments(cursor.getInt(cursor
.getColumnIndex(AppStatsTable.KEY_STATS_COMMENTS)));
info.setVersionCode(cursor.getInt(cursor
.getColumnIndex(AppStatsTable.KEY_STATS_VERSIONCODE)));
stats.init();

info.setRating(
cursor.getInt(cursor.getColumnIndex(AppStatsTable.KEY_STATS_1STARS)),
cursor.getInt(cursor.getColumnIndex(AppStatsTable.KEY_STATS_2STARS)),
cursor.getInt(cursor.getColumnIndex(AppStatsTable.KEY_STATS_3STARS)),
cursor.getInt(cursor.getColumnIndex(AppStatsTable.KEY_STATS_4STARS)),
cursor.getInt(cursor.getColumnIndex(AppStatsTable.KEY_STATS_5STARS)));

info.init();
} while (cursor.moveToNext());

} while (cursor.moveToNext());
}

return stats;
} finally {
if (cursor != null) {
cursor.close();
}
}
}

cursor.close();
public RevenueSummary getRevenueSummaryForApp(AppInfo app) {
Cursor cursor = null;

try {
cursor = context.getContentResolver().query(RevenueSummaryTable.CONTENT_URI,
RevenueSummaryTable.ALL_COLUMNS, RevenueSummaryTable.APPINFO_ID + "=?",
new String[] { Long.toString(app.getId()) }, null);

if (cursor.getCount() == 0) {
return null;
}

if (!cursor.moveToFirst()) {
return null;
}

return info;
int typeIdx = cursor.getInt(cursor.getColumnIndex(RevenueSummaryTable.TYPE));
String currency = cursor.getString(cursor.getColumnIndex(RevenueSummaryTable.CURRENCY));
double lastDay = cursor.getDouble(cursor
.getColumnIndex(RevenueSummaryTable.LAST_DAY_TOTAL));
double last7Days = cursor.getDouble(cursor
.getColumnIndex(RevenueSummaryTable.LAST_7DAYS_TOTAL));
double last30Days = cursor.getDouble(cursor
.getColumnIndex(RevenueSummaryTable.LAST_30DAYS_TOTAL));
RevenueSummary.Type type = RevenueSummary.Type.values()[typeIdx];
RevenueSummary result = new RevenueSummary(type, currency, lastDay, last7Days,
last30Days);

return result;
} finally {
if (cursor != null) {
cursor.close();
}
}
}

@SuppressLint("SimpleDateFormat")
Expand Down
Loading