Skip to content

Commit

Permalink
Test results fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzoPrimi committed Nov 28, 2016
1 parent 8f6be29 commit 9c44f8d
Show file tree
Hide file tree
Showing 25 changed files with 455 additions and 80 deletions.
1 change: 1 addition & 0 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,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
14 changes: 8 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,28 @@
xmlns:tools="http://schemas.android.com/tools"
package="org.openobservatory.ooniprobe">

<uses-sdk tools:overrideLibrary="us.feras.mdv" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk tools:overrideLibrary="us.feras.mdv"/>

<application
android:name="org.openobservatory.ooniprobe.ooniprobeApp"
android:name=".ooniprobeApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="org.openobservatory.ooniprobe.activity.MainActivity">
<activity android:name=".activity.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="org.openobservatory.ooniprobe.activity.SettingsActivity"
android:name=".activity.SettingsActivity"
android:label="@string/settings" />
<activity android:name="org.openobservatory.ooniprobe.activity.InformedConsentActivity"></activity>
<activity android:name=".activity.InformedConsentActivity" />
<activity android:name=".activity.ResultActivity"></activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void update(Observable observable, Object data) {
if (mFinishedTestsListAdapter != null) {
ArrayList finishedTests = TestData.getInstance(this).finishedTests;
ArrayList<NetworkMeasurement> finishedTests = new ArrayList<NetworkMeasurement>(TestData.getInstance(this).finishedTests);
Collections.reverse(finishedTests);
mFinishedTestsListAdapter.setData(finishedTests);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package org.openobservatory.ooniprobe.activity;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.fragment.ResultFragment;
import org.openobservatory.ooniprobe.fragment.ResultListFragment;
import org.openobservatory.ooniprobe.utils.LogUtils;

public class ResultActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
Intent intent = getIntent();
if(intent.getExtras() != null) {
String json_file = intent.getStringExtra("json_file");
final String[] parts = LogUtils.getLogParts(this, json_file);
if (parts.length == 1){
Fragment fragment = new ResultFragment();
FragmentManager fm= getSupportFragmentManager();
FragmentTransaction ft=fm.beginTransaction();
Bundle bundle = new Bundle();
bundle.putInt("position", 0);
fragment.setArguments(bundle);
//ft.remove(fragment);
ft.add(R.id.fragment,fragment);
//ft.replace(R.id.fragment, fragment);
//ft.addToBackStack(null);
ft.commit();
}
else {
Fragment fragment = new ResultListFragment();
FragmentManager fm= getSupportFragmentManager();
FragmentTransaction ft=fm.beginTransaction();
//ft.remove(fragment);
ft.add(R.id.fragment,fragment);
//ft.replace(R.id.fragment, fragment);
//ft.addToBackStack(null);
ft.commit();
}
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
//getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
/*
@Override
public void onBackPressed() {
Fragment fragment=new Fragment1();
FragmentManager fm= getFragmentManager();
FragmentTransaction ft=fm.beginTransaction();
ft.replace(R.id.fragment,fragment);
ft.commit();
}
*/
/*
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
Fragment fragment=new ResultListFragment();
FragmentManager fm= getSupportFragmentManager();
FragmentTransaction ft=fm.beginTransaction();
//ft.remove(fragment);
ft.add(R.id.fragment,fragment);
//ft.replace(R.id.fragment,fragment);
ft.addToBackStack(null);
ft.commit();
return true;
}
if(id == R.id.action_exit)
{
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
}
return super.onOptionsItemSelected(item);
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@

import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper;

/**
* Created by lorenzo on 17/05/16.
*/
public class SettingsActivity extends AppCompatActivity {
SharedPreferences preferences;
RelativeLayout collector_addressLayout;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package org.openobservatory.ooniprobe.adapter;

import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import org.json.JSONException;
import org.json.JSONObject;
import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.fragment.ResultFragment;
import org.openobservatory.ooniprobe.fragment.ResultListFragment;

import java.util.ArrayList;

public class TestResultListAdapter extends RecyclerView.Adapter<TestResultListAdapter.ViewHolder> {


private static final String TAG = TestResultListAdapter.class.toString();

private FragmentActivity mActivity;
private ArrayList<JSONObject> values;
private int context;
TestResultListAdapter.OnItemClickListener mItemClickListener;

public TestResultListAdapter(FragmentActivity context, ArrayList<JSONObject> values) {
this.mActivity = context;
this.values = values;
}

@Override
public TestResultListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_result_test, parent, false);
TestResultListAdapter.ViewHolder vh = new ViewHolder(v);
return vh;
}

@Override
public void onBindViewHolder(TestResultListAdapter.ViewHolder holder, final int position) {
final JSONObject i = values.get(position);
Typeface font = Typeface.createFromAsset(mActivity.getAssets(), "fonts/HelveticaNeue-Roman.otf");
holder.txtTitle.setTypeface(font);
System.out.println(i);
try {
holder.txtTitle.setText("input " + i.getString("input"));
} catch (JSONException e) {
holder.txtTitle.setText("input " + position);
}
try {
if (!i.getJSONObject("test_keys").getBoolean("blocking"))
holder.testStatus.setImageResource(R.drawable.censorship_no);
else
holder.testStatus.setImageResource(R.drawable.censorship_yes);
} catch (JSONException e) {
holder.testStatus.setImageResource(R.drawable.censorship_yes);
}

holder.itemView.setOnClickListener(
new ImageButton.OnClickListener() {
public void onClick(View v) {
Fragment fragment = new ResultFragment();
Bundle bundle = new Bundle();
bundle.putInt("position", position);
fragment.setArguments(bundle);
FragmentManager fm = mActivity.getSupportFragmentManager();
FragmentTransaction ft=fm.beginTransaction();
ft.replace(R.id.fragment,fragment);
ft.addToBackStack(null);
ft.commit();
}
}
);


}

@Override
public int getItemCount() {
return values.size();
}

public void setData(ArrayList<JSONObject> data) {
values = data;
notifyDataSetChanged();

}

public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public TextView txtTitle;
public ImageView testStatus;
public ViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
txtTitle = (TextView) itemView.findViewById(R.id.test_title);
testStatus = (ImageView) itemView.findViewById(R.id.status_image);
}

@Override
public void onClick(View v) {
if (mItemClickListener != null) {
mItemClickListener.onItemClick(v, getAdapterPosition());
}
}
}

public void setOnItemClickListener(final TestResultListAdapter.OnItemClickListener mItemClickListener) {
this.mItemClickListener = mItemClickListener;
}

public interface OnItemClickListener {
void onItemClick(View view, int position);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@

import static org.openobservatory.ooniprobe.R.id.progressBar;

/**
* Created by lorenzo on 26/04/16.
*/
public class TestsAvailableListAdapter extends RecyclerView.Adapter<TestsAvailableListAdapter.ViewHolder> {


Expand Down
Loading

0 comments on commit 9c44f8d

Please sign in to comment.