mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-25 22:01:16 +00:00
Improved usage reporting dialog.
This commit is contained in:
parent
a28987dadf
commit
093afbcb13
2 changed files with 23 additions and 10 deletions
|
@ -6,10 +6,11 @@ import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Build;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
@ -40,6 +41,7 @@ import com.nutomic.syncthingandroid.syncthing.RestApi;
|
||||||
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static java.lang.Math.min;
|
import static java.lang.Math.min;
|
||||||
|
|
||||||
|
@ -58,7 +60,7 @@ public class MainActivity extends SyncthingActivity
|
||||||
*
|
*
|
||||||
* @see #showUsageReportingDialog()
|
* @see #showUsageReportingDialog()
|
||||||
*/
|
*/
|
||||||
private static final long USAGE_REPORTING_DIALOG_DELAY = 3 * 24 * 60 * 60 * 1000;
|
private static final long USAGE_REPORTING_DIALOG_DELAY = TimeUnit.DAYS.toMillis(3);
|
||||||
|
|
||||||
private AlertDialog mLoadingDialog;
|
private AlertDialog mLoadingDialog;
|
||||||
|
|
||||||
|
@ -362,22 +364,32 @@ public class MainActivity extends SyncthingActivity
|
||||||
/**
|
/**
|
||||||
* Displays dialog asking user to accept/deny usage reporting.
|
* Displays dialog asking user to accept/deny usage reporting.
|
||||||
*/
|
*/
|
||||||
@SuppressLint("InflateParams")
|
|
||||||
private void showUsageReportingDialog() {
|
private void showUsageReportingDialog() {
|
||||||
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
getApi().setUsageReportAccepted(
|
switch (which) {
|
||||||
(which == DialogInterface.BUTTON_POSITIVE)
|
case DialogInterface.BUTTON_POSITIVE:
|
||||||
? RestApi.UsageReportSetting.ACCEPTED
|
getApi().setUsageReportAccepted(RestApi.UsageReportSetting.ACCEPTED,
|
||||||
: RestApi.UsageReportSetting.DENIED,
|
|
||||||
MainActivity.this);
|
MainActivity.this);
|
||||||
|
break;
|
||||||
|
case DialogInterface.BUTTON_NEGATIVE:
|
||||||
|
getApi().setUsageReportAccepted(RestApi.UsageReportSetting.DENIED,
|
||||||
|
MainActivity.this);
|
||||||
|
break;
|
||||||
|
case DialogInterface.BUTTON_NEUTRAL:
|
||||||
|
Uri uri = Uri.parse("https://data.syncthing.net");
|
||||||
|
startActivity(new Intent(Intent.ACTION_VIEW, uri));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
getApi().getUsageReport(new RestApi.OnReceiveUsageReportListener() {
|
getApi().getUsageReport(new RestApi.OnReceiveUsageReportListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceiveUsageReport(String report) {
|
public void onReceiveUsageReport(String report) {
|
||||||
|
@SuppressLint("InflateParams")
|
||||||
View v = LayoutInflater.from(MainActivity.this)
|
View v = LayoutInflater.from(MainActivity.this)
|
||||||
.inflate(R.layout.dialog_usage_reporting, null);
|
.inflate(R.layout.dialog_usage_reporting, null);
|
||||||
TextView tv = (TextView) v.findViewById(R.id.example);
|
TextView tv = (TextView) v.findViewById(R.id.example);
|
||||||
|
@ -387,6 +399,7 @@ public class MainActivity extends SyncthingActivity
|
||||||
.setView(v)
|
.setView(v)
|
||||||
.setPositiveButton(R.string.yes, listener)
|
.setPositiveButton(R.string.yes, listener)
|
||||||
.setNegativeButton(R.string.no, listener)
|
.setNegativeButton(R.string.no, listener)
|
||||||
|
.setNeutralButton("Open Website", listener)
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
android:paddingBottom="10dip"
|
android:paddingBottom="10dip"
|
||||||
android:text="@string/usage_reporting_dialog_description" />
|
android:text="@string/usage_reporting_dialog_description" />
|
||||||
|
|
||||||
<HorizontalScrollView android:layout_width="match_parent"
|
<ScrollView android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -21,6 +21,6 @@
|
||||||
android:background="@color/light_grey"
|
android:background="@color/light_grey"
|
||||||
android:padding="5dip"
|
android:padding="5dip"
|
||||||
android:id="@+id/example"/>
|
android:id="@+id/example"/>
|
||||||
</HorizontalScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
Loading…
Reference in a new issue