Skip to content

Commit

Permalink
Settings + bug fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzoPrimi committed Jan 28, 2017
1 parent 0b6a826 commit 5b6cac2
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 139 deletions.
19 changes: 11 additions & 8 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
Expand All @@ -83,6 +75,14 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
Expand All @@ -102,6 +102,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.crashlytics.sdk.android/beta/1.2.3/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.crashlytics.sdk.android/crashlytics-core/2.3.15/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.crashlytics.sdk.android/crashlytics/2.6.6/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.github.AndroidDeveloperLB/AutoFitTextView/4/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/io.fabric.sdk.android/fabric/1.3.15/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/me.panavtec/wizard/1.2/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/uk.co.chrisjenx/calligraphy/2.2.0/jars" />
Expand All @@ -115,6 +116,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" />
Expand Down Expand Up @@ -150,5 +152,6 @@
<orderEntry type="library" exported="" name="appcompat-v7-25.1.0" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-25.1.0" level="project" />
<orderEntry type="library" exported="" name="support-core-utils-25.1.0" level="project" />
<orderEntry type="library" exported="" name="AutoFitTextView-4" level="project" />
</component>
</module>
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apply plugin: 'io.fabric'

repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url "https://jitpack.io" }
}

android {
Expand Down Expand Up @@ -36,4 +37,5 @@ dependencies {
compile('com.crashlytics.sdk.android:crashlytics:2.6.6@aar') {
transitive = true;
}
compile 'com.github.AndroidDeveloperLB:AutoFitTextView:4'
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.json.JSONObject;
import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.fragment.ResultFragment;
import com.lb.auto_fit_textview.AutoResizeTextView;

import java.util.ArrayList;

Expand Down Expand Up @@ -107,13 +108,13 @@ public void setData(ArrayList<JSONObject> data) {
}

public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public TextView txtTitle;
public AutoResizeTextView txtTitle;
public Button viewResult;

public ViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
txtTitle = (TextView) itemView.findViewById(R.id.test_title);
txtTitle = (AutoResizeTextView) itemView.findViewById(R.id.test_title);
viewResult = (Button) itemView.findViewById(R.id.view_button);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
public class TestData extends Observable {
private static final String TAG = "TestData";
private static TestData instance;
private static TestStorage ts;
public static ArrayList<NetworkMeasurement> runningTests;
public static ArrayList<NetworkMeasurement> finishedTests;
public static LinkedHashMap<String, Boolean> availableTests;
Expand All @@ -36,9 +35,8 @@ public static TestData getInstance(final MainActivity a) {
if (instance == null) {
activity = a;
instance = new TestData();
ts = new TestStorage();
runningTests = new ArrayList<>();
finishedTests = ts.loadTests(activity);
finishedTests = TestStorage.loadTests(activity);
availableTests = new LinkedHashMap<>();
availableTests.put(OONITests.WEB_CONNECTIVITY, true);
availableTests.put(OONITests.HTTP_INVALID_REQUEST_LINE, true);
Expand Down Expand Up @@ -67,7 +65,7 @@ public static void doNetworkMeasurements(final Context ctx, final String testNam
final String collector_address = preferences.getString("collector_address", "https://b.collector.ooni.io");
final String max_runtime = preferences.getString("max_runtime", "90");

ts.addTest(ctx, currentTest);
TestStorage.addTest(ctx, currentTest);
runningTests.add(currentTest);
availableTests.put(testName, false);
if (activity != null) TestData.getInstance(activity).notifyObservers();
Expand Down Expand Up @@ -271,7 +269,7 @@ protected void onProgressUpdate(String... values) {
}

protected void onPostExecute(Boolean success) {
ts.setCompleted(ctx, currentTest);
TestStorage.setCompleted(ctx, currentTest);
currentTest.completed = true;
runningTests.remove(currentTest);
finishedTests.add(currentTest);
Expand All @@ -295,8 +293,10 @@ else if(object instanceof Boolean)
anomaly = 0;
else
anomaly = 1;
if (test.anomaly < anomaly)
if (test.anomaly < anomaly) {
test.anomaly = anomaly;
TestStorage.setAnomaly(activity, test.test_id, anomaly);
}
} catch (JSONException e) {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.TimePicker;
import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.core.CrashlyticsCore;

import io.fabric.sdk.android.Fabric;

import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.activity.MainActivity;
Expand All @@ -35,7 +39,7 @@ public class SettingsFragment extends Fragment {
SharedPreferences preferences;
RelativeLayout collector_addressLayout;
RelativeLayout local_notifications_timeLayout;
public static final String DEFAULT_COLLECTOR = "https://a.collector.test.ooni.io";
public static final String DEFAULT_COLLECTOR = "https://b.collector.test.ooni.io";

@Override
public void onAttach(Activity activity) {
Expand Down Expand Up @@ -64,7 +68,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_settings, container, false);
preferences = PreferenceManager.getDefaultSharedPreferences(mActivity);
SwitchCompat include_ipButton = (SwitchCompat) v.findViewById(R.id.ck_include_ip);
final SwitchCompat include_ipButton = (SwitchCompat) v.findViewById(R.id.ck_include_ip);
include_ipButton.setChecked(preferences.getBoolean("include_ip", false));
include_ipButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Expand All @@ -78,7 +82,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
}
});

SwitchCompat include_asnButton = (SwitchCompat) v.findViewById(R.id.ck_include_asn);
final SwitchCompat include_asnButton = (SwitchCompat) v.findViewById(R.id.ck_include_asn);
include_asnButton.setChecked(preferences.getBoolean("include_asn", true));
include_asnButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Expand All @@ -92,7 +96,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
}
});

SwitchCompat include_ccButton = (SwitchCompat) v.findViewById(R.id.ck_include_country);
final SwitchCompat include_ccButton = (SwitchCompat) v.findViewById(R.id.ck_include_country);
include_ccButton.setChecked(preferences.getBoolean("include_cc", true));
include_ccButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Expand All @@ -106,6 +110,24 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
}
});

final SwitchCompat send_crashButton = (SwitchCompat) v.findViewById(R.id.send_crash);
send_crashButton.setChecked(preferences.getBoolean("send_crash", true));
send_crashButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SharedPreferences.Editor editor = preferences.edit();
if (isChecked) {
editor.putBoolean("send_crash", true);
} else {
editor.putBoolean("send_crash", false);
}
editor.commit();
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mActivity);
final Boolean send_crash = preferences.getBoolean("send_crash", true);
CrashlyticsCore core = new CrashlyticsCore.Builder().disabled(send_crash).build();
Fabric.with(mActivity, new Crashlytics.Builder().core(core).build());
}
});

TextView collector_address = (TextView) v.findViewById(R.id.collector_address_subText);
collector_address.setText(preferences.getString("collector_address", DEFAULT_COLLECTOR));

Expand All @@ -116,27 +138,6 @@ public void onClick(View v) {
showPopup();
}
});
if (preferences.getBoolean("upload_results", true))
collector_addressLayout.setVisibility(View.VISIBLE);
else
collector_addressLayout.setVisibility(View.GONE);

SwitchCompat upload_resultsButton = (SwitchCompat) v.findViewById(R.id.ck_upload_results);
upload_resultsButton.setChecked(preferences.getBoolean("upload_results", true));
upload_resultsButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SharedPreferences.Editor editor = preferences.edit();
if (isChecked) {
collector_addressLayout.setVisibility(View.VISIBLE);
editor.putBoolean("upload_results", true);
} else {
collector_addressLayout.setVisibility(View.GONE);
editor.putBoolean("upload_results", false);
}
editor.commit();
}
});

TextView max_runtime = (TextView) v.findViewById(R.id.max_runtimeEditText);
max_runtime.setText(preferences.getString("max_runtime", "90"));
max_runtime.addTextChangedListener(new TextWatcher() {
Expand Down Expand Up @@ -170,11 +171,6 @@ public void onClick(View v) {
showPopup();
}
});
if (preferences.getBoolean("local_notifications", false))
local_notifications_timeLayout.setVisibility(View.VISIBLE);
else
local_notifications_timeLayout.setVisibility(View.GONE);

SwitchCompat local_notificationsButton = (SwitchCompat) v.findViewById(R.id.local_notifications);
local_notificationsButton.setChecked(preferences.getBoolean("local_notifications", false));
local_notificationsButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
Expand Down Expand Up @@ -214,6 +210,47 @@ public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinut
mTimePicker.show();
}
});

SwitchCompat upload_resultsButton = (SwitchCompat) v.findViewById(R.id.ck_upload_results);
upload_resultsButton.setChecked(preferences.getBoolean("upload_results", true));
upload_resultsButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SharedPreferences.Editor editor = preferences.edit();
if (isChecked) {
collector_addressLayout.setVisibility(View.VISIBLE);
include_asnButton.setVisibility(View.VISIBLE);
include_ccButton.setVisibility(View.VISIBLE);
include_ipButton.setVisibility(View.VISIBLE);
editor.putBoolean("upload_results", true);
} else {
collector_addressLayout.setVisibility(View.GONE);
include_asnButton.setVisibility(View.GONE);
include_ccButton.setVisibility(View.GONE);
include_ipButton.setVisibility(View.GONE);
editor.putBoolean("upload_results", false);
}
editor.commit();
}
});

if (preferences.getBoolean("upload_results", true)){
collector_addressLayout.setVisibility(View.VISIBLE);
include_asnButton.setVisibility(View.VISIBLE);
include_ccButton.setVisibility(View.VISIBLE);
include_ipButton.setVisibility(View.VISIBLE);
}
else{
collector_addressLayout.setVisibility(View.GONE);
include_asnButton.setVisibility(View.GONE);
include_ccButton.setVisibility(View.GONE);
include_ipButton.setVisibility(View.GONE);
}

if (preferences.getBoolean("local_notifications", false))
local_notifications_timeLayout.setVisibility(View.VISIBLE);
else
local_notifications_timeLayout.setVisibility(View.GONE);

return v;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ public class ooniprobeApp extends Application {
@Override
public void onCreate() {
super.onCreate();
//Fabric.with(this, new Crashlytics());
//TODO reload with the setting
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
final Boolean send_crash = preferences.getBoolean("send_crash", false);
final Boolean send_crash = preferences.getBoolean("send_crash", true);
CrashlyticsCore core = new CrashlyticsCore.Builder().disabled(send_crash).build();
Fabric.with(this, new Crashlytics.Builder().core(core).build());

Expand Down
Loading

0 comments on commit 5b6cac2

Please sign in to comment.